Using generalized type constraints

In many cases in which we create objects in software engineering, we have dependencies. We either need to have something initialized in order to use a third component, or we require a specific order of initialization, and so on. Both builder pattern implementations we looked at earlier lack the capability to make sure something is or isn't initialized. This way, we need to create some extra validation around the builder design pattern in order to make sure everything will work as expected, yet we will see whether it is safe to create an object only during runtime.

Using some of the techniques we already looked at earlier in this book, we can create a builder that validates whether all requirements are satisfied ...

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.