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.

Complex constructions

Complex constructions - Java Tutorial

From the course: Java Design Patterns: Creational

Start my 1-month free trial

Complex constructions

- [Instructor] The builder pattern can also be used for when the program has complex constructions. In this example, the architect class is used to create a house. The house takes a list of rooms as its constructor. The room objects are created using a room builder class, which is good, because that means there is no need to use a long and complex constructor. The rooms can have as many or few characteristics specified as needed. However, creating a house is still quite complex. Each new room has to be created individually. Then, a new array list has to be created to store the rooms. And then, each room needs to be added to that array list. Only then can a house object be created. The builder pattern has already been used to simplify creating a room, but it can be used again, to simplify this further. The application also has a class called RoomListBuilder, which builds the list of rooms. The first method declared in this class is called addList, and this returns a new array list to…

Contents