The Abstraction Principle advocates decoupling the interface and implementation of a class. The Subsumption Rule facilitates abstraction. For example, the declaration:
List names;
Hides the particular implementation of the List interface that will be used: ArrayList or LinkedList. The client can add and remove names from the list without regard to the implementation. However, the implementation is unmasked when the instantiate the list:
names = new ArrayList<String>();
How can this unmasking be prevented? There are several design patterns that have as their goal hiding the way objects are created. These patterns include:
Normally we create many instances of a class. In some cases we may want to control the number of instances created. The following patterns address this issue:
Many of these patterns can be seen in the MazeMaker case study.