From the course: Java Design Patterns: Creational

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Implement the Builder pattern

Implement the Builder pattern - Java Tutorial

From the course: Java Design Patterns: Creational

Start my 1-month free trial

Implement the Builder pattern

- [Instructor] In this example, there is an application with a complex constructor that will benefit from using the builder pattern. The application has a class called Bedroom which has eight different fields. It also has an Architect class that can be used to create Bedroom objects. In the application's current state, it is only possible to create a Bedroom if all eight pieces of information are supplied. None of them are optional, because they are all used in the single constructor of the Bedroom class. It is also very difficult to tell what all the different information is about when a Bedroom object is created. It is also a requirement of this application to have flexibility. It should be able to create a Bedroom with any combination of these pieces of information. One option is to go about implementing a different constructor for all of the implementations. This would take a very long time to write out, and make our room class very long and messy. A better idea is to implement…

Contents