A modular design for a webpage
June 28, 2007 3:39 AM   Subscribe

What's the best way of designing a modular webpage that is intended to be used by plugins?

I want to design a simple page which calls different plugins one after the other to display data. For example, I'm designing a general knowledge Exam. The exam framework is what I want to design. The actual questions are the plugins, and they can be designed independently of the framework, and then plugged in.

What would be a good design pattern to go about this?

How do I deal with the issue of access to the database by the plugins without breaking the independence of the plugins? How do I design a mode where I know which plugin wants to be displayed when?
posted by markovich to Computers & Internet (3 answers total)
 
I don't know what the design pattern would be, bit you basically need to do discovery of what plugins are available to you, and have each plugin expose a standard interface.

Your core application iterates over the plugins, setting/getting data in them via this standard interface.

PHP-leaning example:

Plugins are stored in /plugins

Each plugin must be named PluginName.php

Each plugin must contain a class PluginName

The constructor of each class must be in the form PluginName ($dbconn) (passing the DB connection into the class)

Each plugin must expose a public method iWantToTalk() which returns true when the plugin is ready to spit out data

I'm sure you get the idea. Create an abstract class for each plugin to inherit, so it's fulfilling some kind of contract. Iterate over /plugins to get a list of filenames, require() each filename in turn and instantiate its class.
posted by Leon at 3:58 AM on June 28, 2007


You should look into Django.
posted by miniape at 5:17 AM on June 28, 2007


The real answer to this is to put the "plugins" (questions) in the database. There isn't any need for them to be hardcoded and modular.
posted by tmcw at 10:43 AM on June 29, 2007


« Older FontFilter: What font is this?   |   Why, body, why? Newer »
This thread is closed to new comments.