Composite Design Pattern using Java and Database

Compositecomposite Design Pattern helps the developer to abstract an information tree structure in code. The following example shows how to use in a Hierarchical Filter need.

The main idea here is to present how to use it, if you want a background on composite pattern, I recommend Gamma et al. book [1]. The diagram to present the composite is the follow, for this diagram I use OPM (Object Process Methodology) [2] which shows a Hierarchical Flow process containing multiple Filters subprocesses which is invoked by it.

composite-design-pattern-for-hierarchical-flow

Figure 1 – Composite design pattern

The implementation requires two steps the pattern coding, the controller coding for filter and flow loading.

<Next writing topic>

Jumping to controller implementation. The controller will load the composite classes according to database configurations. As first step the configuration of the composite hierarchy is needed, the suggestion here is to keep the configuration inside the database as an entity relationship model. Database tables will provide the model for further view (e.g., JSON) implementation. The following diagram show how use a composite within conjunction with traditional database implementation.

Configuring-and-using-a-composite-class

Figure 2 – Business Controller in conjunction with Composite Pattern

The configuring process can be implemented using database as data source which will store all composite information.

References:

[1]Design Patterns: Elements of Reusable Object-Oriented Software

[2]Object-Process Methodology: A Holistic Systems Paradigm

Última atualização: 20/Set/2015