Template
The next pattern that we are going to analyze is called Template and it has a lot in common with the Strategy pattern. The Template pattern defines an abstract class that implements the skeleton (representing the common parts) of a component, where some of its steps are left undefined. Subclasses can then fill the gaps in the component by implementing the missing parts, called template methods. The intent of this pattern is to make it possible to define a family of classes that are all variations of a family of components. The following UML diagram shows the structure that we just described:
Figure 9.4: UML diagram of the Template pattern
The three concrete classes shown in Figure 9.4, extend the template class and provide an implementation for templateMethod()
, which is abstract or pure virtual, to use C++ terminology. In JavaScript, we don't have a formal way to define abstract classes, so all we can do is leave...