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 ...

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