views:

197

answers:

5

In my analysis of the newer web platforms/applications, such as Drupal, Wordpress, and Salesforce, many of them create their software based on the concept of modularization: Where developers can create new extensions and applications without needing to change code in the "core" system maintained by the lead developers. In particular, I know Drupal uses a "hook" system, but I don't know much about the engine or design that implements it.

If you were to go down a path of creating an application and you wanted a system that allowed for modularization, where do you start? Is this a particular design pattern that everyone knows about? Is there a handbook that this paradigm tends to subscribe to? Are their any websites that discuss this type of development from the ground-up?

I know some people point directly to OOP, but that doesn't seem to be the same thing, entirely.

This particular system I'm planning leans more towards something like Salesforce, but it is not a CRM system.

For the sake of the question, please ignore the Buy vs. Build argument, as that consideration is already in the works. Right now, I'm researching the build aspect.

A: 

If you're hosting the application, publish (and dogfood) a RESTful API.

If you're distributing software, look at OSGi.

Hank Gay
+1  A: 

The Plugin pattern from P of EAA is probably what you are after. Create a public interface for your service to which plugins (modules) can integrate to ad-hoc at runtime.

Eran Galperin
+1  A: 

This is called a component architecture. It's really quite a big area, but some of the key important things here are:

  • composition of components (container components can contain any other component)
    • for example a grid should be able to contain other grids, or any other components
  • programming by interface (components are interacted with through known interfaces)
    • for example a view system that might ask a component to render itself (say in HTML, or it might be passed a render area and ask the view to draw into it directly
  • extensive use of dynamic registries (when a plugin is loaded, it registers itself with the appropriate registries)
  • a system for passing events to components (such as mouse clicks, cursor enter etc)
  • a notification
  • user management

and much much more!

Jesse Pepper
+5  A: 

There are two ways to go around here, which one to take depends on how will your software behave.

One way is the plugin route, where people can install new code into the application modifying the relevant aspects. This route demands your application is installable and not only offered as a service (or else that you install and review code sent in by third parties, a nightmare).

The other way is to offer an API, which can be called by the relevant parties and make the application transfer control to code located elsewhere (a la Facebook apps) or make the application to do as the API commands enable the developer (a la Google Maps).

Even though the mechanisms vary and how to actually implement them differ, you have to, in any case, define

  • What freedom will I let the users have?
  • What services will I offer for programmers to customize the application?

and the most important thing:

  • How to enable this in my code while remaining secure and robust. This is usually done by sandboxing the code, validating inputs and potentially offering limited capabilities to the users.

In this context, hooks are predefined places in the code that call all the registered plugins' hook function, if defined, modifying the standard behavior of the application. For example, if you have a function that renders a background you can have

function renderBackground() {
    foreach (Plugin p in getRegisteredPlugins()) {
        if (p.rendersBackground) p.renderBackground();
    }
    //Standard background code if nothing got executed (or it still runs, 
    //according to needs)
}

In this case you have the 'renderBackground' hook that plugins can implement to change the background.

In an API way, the user application would call your service to get the background rendered

//other code
Background b = Salesforce2.AjaxRequest('getBackground',RGB(255,10,0));
//the app now has the result of calling you

This is all also related to the Hollywood principle, which is a good thing to apply, but sometimes it's just not practical.

Vinko Vrsalovic
Great answer. Thanks!
wrburgess
A: 

Here's a small video that at least will give you some hints; the Lego Process [less than 2 minutes long]

There's also a complete recipe for how to create your own framework based extensively on Modularization...

The most important key element to make modularized software is to remember that it's purely [mostly] a matter of how loosely coupled you can create your systems. The more loosely coupled, the easier it is to modularize...

Thomas Hansen