Treating objects the same way using the composite pattern
The composite pattern is a remarkable solution for handling objects uniformly while arranging them in a tree structure, which simplifies access to instances. The demand for it naturally came from industry, and the pattern was soon identified and described by the GoF.
Motivation
Grouping objects around the underlying business logic is a powerful approach. A composite design pattern outlines a way to achieve such a state. Since each member of the group is treated uniformly, it is possible to create hierarchical tree structures and part-whole hierarchies. It helps to establish the logical relationships of the application and the composition of the desired objects.
Finding it in the JDK
In the JDK, the composite pattern can be found in the java.base
module, the java.util
package, and the Properties
class. The Properties
class implements the Map
interface through its Hashtable
implementation, and also contains a ConcurrentHashMap...