Question

I have create some programs but most of them are based on a 'spaghetti' approach. All features are together, and if I wanted to add a new feature I have to add it to the core files.

Notice: I am not asking about separating design and logic.

The language is PHP.

What I am asking about is what are the approaches (and how to achieve them) used in Content Management Systems by allowing an application to be extended by other users (plugins, components or extensions)

Is it just a matter of a design pattern? Or file structures? or what?

Was it helpful?

Solution

First of all you have to make decisions about locations for plugin behavior in your software architecture. Then you have to define an interface for these plugins. After that you have to build an interface for registering plugins.

Interceptor Pattern is your friend for running registered plugins on any location in your application.

You should define a strategy to prioritize executing plugins in a queue. Strategies can be FIFO (FirstInFirstOut) or allowing an userdefined order.

In addition you should define a strategy to handle errors and exceptions thrown by any plugin to ensure a running system.

This represents only a rough concept, but contains the core elements for a plugin-able application.

A good example in PHP for an easy access can be ZendFramework1. It's using a simple plugin broker for dispatch process in FrontController. How it works is good descripted here and good illustrated here. But you have to know it exists better approaches, e.g. aspect-oriented programming (AOP). AOP in PHP is reachable by event-driven programming (EDP) or reachable by using external packages, like AOP-PHP.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top