Template method pattern
The Template Method (english template method pattern ) is employed in the software development design patterns that can be variable with the sub-steps of an algorithm. It belongs to the category of behavior patterns ( engl. behavioral patterns ). The pattern is one of the so-called quad -band design patterns ( GoF ).
In stencil methods design pattern the skeleton of an algorithm is defined in an abstract class. The concrete transformation of the individual steps is delegated to subclasses. This provides the possibility to change the individual steps of the algorithm or overwrite without the underlying structure of the algorithm needs to be modified. The template method (English template method) calls abstract methods that are defined only in the subclasses. These methods are also referred to as insertion methods.
In addition Hook - operations can be invoked in the template method at certain locations, whose default implementation in the abstract class does nothing. In this way, you can at predefined points in the algorithm to insert additional functionality.
As a variant of the insertion methods or operations hook may also have a default implementation that can be used by the concrete classes, but do not necessarily.
An example of this is found in the I / O data flow programming of Java. There implements an output stream containing a concrete methodology for writing a byte array. This method uses a method to write a single byte to write the entire array one by one. However, the method for the single byte is still abstract because an OutputStream itself is not specific. Classes like FileOutputStream can implement this method. Then you inherit an already implemented method for writing a byte array.
Policy -Based Design
Policy -Based Design is a more general design patterns, in which not only algorithms but all classes are built stereotyped. Both methods or algorithms as well as stored data, base classes and interfaces are then interchangeable within the skeletal structure. This generally requires Templatemetaprogrammierung as they are in C and D, however, is theoretically also constructs some scripting languages ( eval, macros, autoloading of source code etc.)., Although rarely in languages like C # or Java feasible.
The rough process of a board game like chess or Monopoly always looks the same: It is a very welcome and the board is set up. The players are in turn so long on the train until the game is finished. Finally, the winner is determined.
The skeleton always this same algorithm can be implemented in its fundamentals in a template method of an abstract class Game. To implement now a specific game, the abstract methods of the template method have ( that differ for each board game itself ) are in a concrete child class implements. Here is an example in C .