How to design extensible software (plugin architecture)? [closed]

Solution 1:

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

  • ClearScript - Makes V8, VBScript and JScript available to .NET apps
  • CS-Script - The C# Script Engine
  • Plugin Architecture using C#
  • Opinio plugin architecture
  • Notes on the Eclipse Plug-in Architecture
  • Plug-in Architecture Framework for Beginners
  • Gecko plugin architecture
  • Fungimol plugin architecture

Solution 2:

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.

Solution 3:

Implement SOLID principles in your application.

1. Single responsibility principle: A class should have only a single responsibility (i.e. only one potential change in the software's specification should be able to affect the specification of the class

2.Open/closed principle: Software entities … should be open for extension, but closed for modification

3. Liskov substitution principle: Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program

4. Interface segregation principle: Many client-specific interfaces are better than one general-purpose interface

5. Dependency inversion principle: One should Depend upon Abstractions. Do not depend upon concretions

Stackoverflow questions:

Example of Single Responsibility Principle

Is the Open/Closed Principle a good idea?

What is the Liskov Substitution Principle?

Interface Segregation Principle- Program to an interface

What is the Dependency Inversion Principle and why is it important?

Solution 4:

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.