You are here

Template Method Pattern: Expressing Invariant Behavior in terms of Variant Behaviors

15 January, 2016 - 09:02
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://cnx.org/contents/402b20ad-c01f-45f1-9743-05eadb1f710e@37.6
Note: The code for the classes AFrame, FrameA, FrameAB, and FrameAC are available in the glossary.

The code for AFrame is an example of what is called the Template Method Pattern. This design pattern is used to expresses an invariant and concrete behavior that consists of calls to one or more abstract methods. An abstract method represents a variant behavior. In other words, the template design pattern is a means to express an invariant behavior in terms of variant behaviors. We shall see this pattern used again in expressing sorting algorithms.