The template method pattern

The template method pattern basically defines the steps of an algorithm inside a class as a contract while deferring some of the steps (methods) to be implemented by the derived classes; hence, it primarily defines the structure via an abstract base class.

We will explain its implementation using an example in continuation of our sample for a GUI app we created earlier for the abstract factory pattern. In fact, within the same example app, we cover abstract factory, builder, and template method patterns.

In the abstract factory example, we presented the IUIAbsFactory interface and mentioned two of the possible implementations as DarkUIAbsFactory and LightUIAbsFactory concrete factory classes. Since the difference ...

Get Enterprise Application Architecture with .NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.