The fact that software development is an extremely broad topic leads to a number of things that can be done with programming. Requirements can vary greatly between different industries and engineering teams. These facts have caused many different design patterns to be invented. This is further contributed to by the existence of various programming languages with different features and levels of expressiveness.
This book focuses on the design patterns from the point of view of Scala. As we mentioned previously, Scala is a hybrid language. This leads us to a few famous design patterns that are not needed anymore—one example is the null object design pattern, which can simply be replaced by Scala's Option. Other design patterns become possible using different approaches—the decorator design pattern can be implemented using stackable traits. Finally, some new design patterns become available that are applicable specifically to the Scala programming language—the cake design pattern, pimp my library, and so on. We will focus on all of these and make it clear where the richness of Scala helps us to make our code even cleaner and simpler.
Even if there are many different design patterns, they can all be grouped in the following:
- Creational
- Structural
- Behavioral
- Functional
- Scala-specific design patterns
Some of the design patterns that are specific to Scala can be assigned to the previous groups. They can either be additions or replacements of the already existing ones. They are typical to Scala and take advantage of some advanced language features or simply features not available in other languages.
The first three groups contain the famous Gang of Four design patterns. Every design pattern book covers them and so will we. The rest, even if they can be assigned to one of the first three groups, will be specific to Scala and functional programming languages. In the next few subsections, we will explain the main characteristics of the listed groups and briefly present the actual design patterns that fall under them.