Book Image

Scala Design Patterns

By : Ivan Nikolov
Book Image

Scala Design Patterns

By: Ivan Nikolov

Overview of this book

Scala has become increasingly popular in many different IT sectors. The language is exceptionally feature-rich which helps developers write less code and get faster results. Design patterns make developer’s lives easier by helping them write great software that is easy to maintain, runs efficiently and is valuable to the company or people concerned. You will learn about the various features of Scala and be able to apply well-known, industry-proven design patterns in your work. The book starts off by focusing on some of the most interesting features of Scala while using practical real-world examples. We will also cover the popular "Gang of Four" design patterns and show you how to incorporate functional patterns effectively. By the end of this book, you will have enough knowledge and understanding to quickly assess problems and come up with elegant solutions.
Table of Contents (20 chapters)
Scala Design Patterns
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
Index

The stackable traits design pattern


There are sometimes cases where we want to be able to provide different implementations for a method of a class. We might not even know all the possibilities that could exist at the moment of writing, but we can add them later and combine them together. Or we can allow someone else to do this instead. This is another use case of the decorator design pattern, which for this purpose could be implemented with the stackable traits design pattern. We have already seen this pattern before in this book in Chapter 7, Structural Design Patterns, but we used it to read data, which adds a really important catch there. We will see another example here, which will make sure everything is completely clear.

Using stackable traits

The stackable traits design pattern is based on mixin composition—something we became familiar with in the early chapters of this book. We usually have an abstract class or a trait that defines an interface, a base implementation, and traits that...