Summary

In this chapter, we familiarized ourselves with some concepts that help us to write better, more generic, and extendible software. We focused on abstract types, polymorphism, and self types in Scala.

We looked into the differences between generics and abstract type values in classes, along with some examples and usage advice. Then, we introduced the different types of polymorphism—subtype, parametric, and ad hoc. Finally, we went through self types in Scala and how to use them. We showed that self types provide a good way to encapsulate functionality and write modular code.

In the following chapter, we will look into the importance of separating the responsibilities of software components. We will also go through aspect-oriented programming. ...

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.