• Albert Bennett

Design Patterns: Template Method

Updated: Jul 12, 2021

As always here is the link to the GitHub repo :)

If this post has helped you feel free to like, comment and share.

This pattern is about defining the order in which methods need to be called, whilst letting sub-classes define the actual behaviors. The diagram below show how this fits together:

Essentially our AbstractClass defines the order in which functions are executed in the TemplateMethod. Whereas sub-classes define the actual behavior of the method.

Here is an example of how this pattern would be implemented. Notice how instead of calling multiple methods from various different objects we only call the one on the template object. Thus simplifying our code.

I hope that this helps you to understand the Template Method pattern. See you next time.

ᕕ( ᐛ )ᕗ

<< More Design Patterns

4 views0 comments

Recent Posts

See All