views:

2430

answers:

10

I need some resources that talk about how to design your software to be extensible, i.e. so that other people can write add-ons/plug-ins that adds functionality to it.

What do you recommend? Any books out there that discuss the subject?
I would prefer something that's short and to the point; a bit of theory and a bunch of concrete examples.

I'm not targeting a specific language, I want to be able to understand the core idea so that I can implement it in any language.

And for the same reason, I prefer not to do it using a framework that someone else built (unless the framework is not very high-level, i.e. doesn't hide too much), at the moment I only want to educate myself on the subject and experiment with various ways to implement it. Plus, a framework usually assumes user's knowledge about the subject.

UPDATE

I'm not asking about OOP or allowing my classes to be inherited. I'm talking about designing an application that will be deployed on a system, such that it can be extended by third-party addons AFTER its been deployed.

For example, Notepad++ has a plug-in architecture where u place a .dll file in the plugins folder, and it adds functionality to the application that wasn't there, such as color-picking, or snippet insertion, or many other things (a wide range of functionality).

+4  A: 

OSGI is a good practical example of a technical framework allowing to do what you are after.

The theory is here.

The (free!) book is there.

Extensibility and the ability to write plugin must deal with service lifecycle

  • adding / removing service/plugin on the spot
  • managing dependencies between services
  • managing states of services (declared, installed, started, stopped,...)

What is OSGI for ?

One of the main functions of a module is as a unit of deployment… something that we can either build or download and install to extend the functionality of our application.

You will find a good introduction here, on the central notion of service (which is related to your question, and which explain some problems around services, key component for extensibility).

Extract:

Why are services then so important if so many applications can be built without them? Well, services are the best known way to decouple software components from each other.

One of the most important aspects of services is that they significantly minimize class loading problems because they work with instances of objects, not with class names. Instances that are created by the provider, not the consumer. The reduction of the complexity is quite surprising

Not only do services minimize configuration, they also significantly reduce the number of shared packages.

VonC
What's osgi? I looked at the website but I don't get how is it related to my question!
hasen j
Look at this http://stackoverflow.com/questions/106222/what-does-osgi-solve
victor hugo
+6  A: 

IF we're talking .NET, try Scripting .NET applications with VBScript over on CodeProject. Lots of concrete examples there.

Below are sites implementing various application extension techniques

boost
Spooky, the Plugin Architecture using C# link is to code that looks exactly like a POC I once wrote. Only one thing was missing: A filesystemwatcher to pick up new modules during runtime. Great for demo's: "Put the dll in this directory and... Voila! A new menu choice."
Guge
accepted because of this link http://www.codeguru.com/cpp/misc/misc/plug-insadd-ins/article.php/c3879 which I didn't notice at first!
hasen j
Thanks. Asante. Shukria. Shukran. Tenkyu tru. Obligad. Merci. Gracias. Arigato. Xie xie. Navazish.
boost
really interesting stuff! thanks!
Sander Versluys
A: 

Rather than re-inventing the wheel, use the frameworks in hand. Eclipse and Netbeans both support plugin based extensions. You have to work in Java though.

questzen
A: 

Checkout "CAB" - Microsoft's Composition Application Building blocks Framework. I think they've got a "web version" of that too...

Thomas Hansen
A: 

I have just started to develop a smart client application. These are two options I am considering.

Using Microsoft's System.AddIn namespace. Looks very promising, however it may be a little complex for our end solution.

Or the Smart Client - Composite UI Application Block from Microsoft

Recently, i have looked at taking components both the Composite UI Application Block and the System.AddIn namespace to build my own. Since source code is available for the CAB it is easy to extend. I think our end solution will be a light weight version of the CAB, definatly using the Unity Application Block

Rohan West
+1  A: 

Of course there is the famous Open Closed Principle - http://en.wikipedia.org/wiki/Open/closed_principle

LenW
+2  A: 

You try to reach two competing goals:

  1. The components of your software must expose a lot of themselves, so they can be reused
  2. The components of your software must expose very little of themselves, so they can be reused

Explanation: To encourage code reuse, you should be able to extend existing classes and call their methods. This isn't possible when the methods are declared "private" and the classes are "final" (and can't be extended). So to meet this goal, everything should be public and accessible. No private data or methods.

When you release the second version of your software, you will find that many of the ideas of version 1 were plain wrong. You need to change many interfaces or your code, method names, delete methods, break the API. If you do this, many people will turn away. So in order to be able to evolve your software, the components must not expose anything that is not absolutely necessary - at the cost of code reuse.

Example: I wanted to observe the position of the cursor (caret) in an SWT StyledText. The caret is not meant to be extended. If you do it, you'll find that the code contains checks like "is this class in the package org.eclipse.swt" and a lot of methods are private and final and whatnot. I had to copy about 28 classes out of SWT into my project just to implement this feature because everything is locked down.

SWT is a nice framework to use and hell to extend.

Aaron Digulla
A: 

Plugin architecture is becoming very popular for its extensibility and thus flexibility.

For c++, Apache httpd server is actually plugin based, but a concept of module is used instead. Most of apache features are implemented as modules, like cache, rewrite, load balancing, and even threading model. It is a very modular software I ever saw.

And for java, Eclipse is definitely plugin based. The core of Eclipse is an OSGI module system which manage bundles, another concept for plugin. Bundle can provide extension points on which we can build modules with less efforts. The most intricate thing in OSGI is its dynamic characteristic, which means bundles can be installed or uninstalled at runtime. No stop-the-world syndrome any more!

yanky
A: 

The article Writing Plugin-Based Applications clearly explains the responsibilities of the various parts of the architecture using a very simple example; source code is provided (VB.Net). I found it very helpful in understanding the basic concepts.

Tom Juergens
+1  A: 

Well it depends on the language.

  • In C/C++ I'm pretty sure there is a loadlibrary function that allows you to open a library at runtime and invoke it's exported functions. This is typically how it's done in C/C++.
  • In .NET, there is Reflection, which is offers similar (but more broad) to loadlibrary. There is also entire libraries built on Reflection like Managed Extension Framework, or Mono.Addins that does most of the heavy lifting for you already.
  • In Java, there is also Reflection. And there is the JPF (Java Plugin Framework) which is used in stuff like Eclipse IIRC.

Depending on what language you use I could recommend some tutorial/books. I hope this was helpful.

joemoe