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 a complete Builder pattern - Java Tutorial
From the course: Java Design Patterns: Creational
Implement a complete Builder pattern
- [Instructor] In this section, I will refactor the example application to create a more complete builder pattern. Currently, it uses a simple builder to create bedroom objects. The Architect class creates bedroom objects by specifying the characteristics of the bedrooms that are needed, however, it would be useful if it was possible to create different kinds of rooms, such as kitchens, bathrooms and so on. In the classic builder pattern, the Builder class is actually an abstract interface. In this example, there could be an interface that defines methods for building rooms in general, and there could be different concrete builders for different types of rooms. This would be useful because building a bedroom has some of the same requirements for building a kitchen, but in some respects, is very different. To achieve this, the first thing we need to do is to create the abstract interface. In NetBeans, it is easy to create an interface from an existing class. On the left of the screen…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.