Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Module Coding techniques

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
US
I posted something similar in the Puzzles for Programmers forum about three weeks ago...I got one reply directing me to post it here before the post was deleted. Ouch. I don't think that this is the right forum but I am just doing what I was told.

I am looking to learn about modulized code practices. I have never worked for 'Big Software' and I might never get the 'privilege' of being a minion. :) The disadvantage is that I have never learned to write modulized code.

Let me be more specific. I am not talking about writing re-usable code. I am talking about systems like big blog engines or CMS's that have code modules or plugins. I can go to their projects and find out how they do it, sure, but I am hoping to get a book or at least some good documentation on best practices for writing code that can be dramatically altered by the use of plugins/modules.

Does anyone have any pointers, good books, or web-resources on this topic? I'd really like to see a few different approaches documented and implemented in psuedo-code or something.

Thanks

Robert Carpenter
Remember....eternity is much longer than this ~80 years we will spend roaming this earth.
ô¿ô
 
I'm not sure there's really much to this topic. What they seem to do is to simply use DLLs for the code itself, query what is found in the directory, and then dynamically load/call whatever is configured.

For example, I wrote a little testing program for sorting algorithms. I don't have to modify the testing program at all. If I want to add a new implementation of an algorithm, I code a DLL with the standards dictated by the testing program. Then when the testing program loads, it searches its directory for DLLs and then calls an id function.

For all the successful calls of the id function it loads the identifier (for example, QSORT.DLL returns "Quicksort")returned into a visible list (along with the DLL name in the background). Then the specific id can be selected and the tests run against it (again calling a known function type in the DLL).

The only key to it is having a specific standard which fits into your logic.

----------
Measurement is not management.
 
Glen9999-

Okay, I see how that can work for simple programs (eg. your sort testing program), but lets put this example in:

If I write the software for a blog and I know that later I am going to want to be able to add hooks for plugins to be added later, but I don't know where I'll need to add a plugin, how can I know where to put the module loading routine in?

Furthermore, what if my plugin needs to be executed in a particular step of the program flow? Eg. what if I want to write a plugin that will make my blog send an email to me when somebody posts a comment. I'd then have to open up the primary source code and put in a directory for the event "when somebody posts a comment" and tell the primary code to look there for modules....at that point I have done enough coding to have just put the new functionality into the primary codebase instead of into a plugin.

If that makes sense, how can I pull that off?

Robert Carpenter
Remember....eternity is much longer than this ~80 years we will spend roaming this earth.
ô¿ô
 
It is all a bit language-dependent, so it may help to say what language you program in.

PHP, for instance, has a nice feature of allowing a return value from an included file. So you can put your plug-in in a directory and have it return an instance of the plug-in object.

your application can off course define a superclass with all sorts of methods that the plug-in can use or override.

In short: the plugin has to have some sort of predefined structure, otherwise your program does not know when to call what on the plug-in. The plug-in then just defines or overrides the details.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top