Wrapping Up

In this chapter, we explored an interesting and powerful Scala feature that promotes extensibility. Traits are a great design tool to create extensible code with dynamic behavior beyond what’s provided by one single class. They nicely avoid method collisions when multiple implementations are brought together. You saw how powerful patterns like the Decorator pattern can be elegantly implemented with traits.

In the next chapter, we’ll take a look at Scala’s support for collections of objects.

Get Pragmatic Scala 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.