In this video, learn how to use the Builder pattern with more complex constructions. Learn how the Builder pattern can be used to simplify adding objects to collections.
- [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 store rooms in.…
The second method adds a room to this list.…
- What are creational design patterns?
- Avoid complex constructors
- Implementing the Builder pattern
- Multithreading with the Singleton pattern
- Using the Prototype pattern
- Implementing a simple Factory Method pattern
- Making code more flexible with the Abstract Factory pattern