Adding generalized type constraints to the required methods

What we have so far, however, is still not going to satisfy our requirements regarding what every Person object should have initialized. We would have to change some methods in the PersonBuilder class. These methods are setFirstName, setLastName, and build. Here are the changes to the set methods:

def setFirstName(firstName: String): PersonBuilder[HasFirstName] = {  this.firstName = firstName  new PersonBuilder[HasFirstName](this)}def setLastName(lastName: String): PersonBuilder[HasLastName] = {  this.lastName = lastName  new PersonBuilder[HasLastName](this)}

The interesting part comes with the build method. Let's have a look at the following initial implementation:

def build()(implicit ...

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.