Builder (Chapter 15)

SOLUTION 15.1The point of making the Reservation constructor protected is that it limits the ability to instantiate your class. You want to compel other developers to create Reservation objects with a builder rather than with the Reservation constructor. You could make the constructor package protected, which would ensure that only other classes within your package can construct Reservation objects. Making the constructor protected leaves open the possibility of subclassing Reservation from another package. Note that making the constructor's visibility private would break the builder classes' ability to instantiate the Reservation class.
SOLUTION 15.2The build() method of UnforgivingBuilder throws an exception if any attribute ...

Get Design Patterns Java™ Workbook 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.