Choosing a design pattern

As we already saw, there are a huge number of design patterns. In many cases, they are suitable to be used in combinations as well. Unfortunately, there is no definite answer regarding how to choose the concept of designing our code. There are many factors that could affect the final decision, and you should ask yourselves the following questions:

  • Is this piece of code going to be fairly static or will it change in the future?
  • Do we have to dynamically decide what algorithms to use?
  • Is our code going to be used by others?
  • Do we have an agreed interface?
  • What libraries are we planning to use, if any?
  • Are there any special performance requirements or limitations?

This is by no means an exhaustive list of questions. ...

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.