Example class diagram

The template method design pattern is suitable for implementing frameworks. A typical thing here is that algorithms usually perform the same set of steps, and then these steps are implemented differently by different clients. You can come up with various possible use cases.

For our example, let's imagine that we want to write an application that will read some data from a data source, parse it, and find whether there is an object that satisfies some condition and returns it. If we think about it, we have the following main operations:

  • Read the data
  • Parse the data
  • Search for items satisfying the condition
  • Clean up any resources if needed

The following diagram shows the class diagram of our code:

We have used an example ...

Get Scala Design Patterns - Second Edition 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.