There is always a need to develop component based architecture with a flexibility to have loosely coupled units. While it is perfectly valid that a component may be dependent upon an output produced by another component, it shouldn’t be aware of how and from where the data is retrieved. The task of fetching data and performing operations on the data must be completely isolated from each other.
One more common thing that I have noticed over past few years is that, if there are multiple activities performed while serving any request, facade is considered to be widely accepted pattern to abstract all the complexities. Though it seems to be perfect choice to implement such series of operations via Facade pattern, the most flexible architecture would go one step further and allow wiring of such components through configuration making it much flexible to add/remove components – Chain of components.
The approach of configuring components through a configuration file would serve following purposes
1. Adding any new functionality would require building new component and plugging it into the configuration chain. This will not affect existing code.
2. Removing any undesired functionality would require removing definition of component from configuration file.
3. Unit testing of component would be easier as it works only on the data made available to it.
In building new architecture for our existing system, we thought of above approach and did some googling to find out if there is any readymade framework which would serve this purpose. After spending few hours, we found http://commons.apache.org/chain/ which was quite resembling to the concept, we thought of.
Common chain follows, a very popular design pattern – Chain of Responsiblity. It’s easy to use implementation and flexible configuration was meeting almost 75% of our expectation. The only feature that it didn’t provide is logically combining output produced by different components as per application requirement.
With respect to the output requirements, we had following three criterias and to meet these requirements we created our own framework on top of Common chain.