Building under Constraints

You want to ensure that invalid Reservation objects are never instantiated. Specifically, suppose that every reservation must have a non-null date and city. Further, suppose that a business rule states that Oozinoz will not perform for fewer than 25 people or for less than $495.95. To support this rule, you can create a ReservationConstants interface:

public interface ReservationConstants
{
     public static final int MINHEAD = 25;
     public static final double MINTOTAL = 495.95;
}

A reservation for too small an audience or that generates too little income is invalid. To avoid creating an instance of Reservation when a request is invalid, you might place business logic checks and exception throwing in the constructor for ...

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.