From the course: Java Design Patterns: Creational

Unlock the full course today

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

Implement the Abstract Factory pattern

Implement the Abstract Factory pattern - Java Tutorial

From the course: Java Design Patterns: Creational

Start my 1-month free trial

Implement the Abstract Factory pattern

- [Instructor] In this example the Bike Builder application shows how the abstract factory pattern can be used. The application builds bike parts, either for mountain bikes or road bikes. First of all, there are a couple of abstract classes called Tire and Handlebar. These are parts of the bike and they are abstracts because different types of bike will have different concrete implementations. They both have one abstract method: getDescription. Then there are two more classes called Mountain Bike Tire and Road Bike Tire. These are the concrete implementations of the abstract tire class. Both Mountain Bike Tire and Road Bike Tire provide implementations of the getDescription method. These are slightly different because the Mountain Bike Tire class prints out both the width and the pressure; Road Bike Tire only prints out the width. There are also two classes called Mountain Bike Handlebar and Road Bike Handlebar. These are concrete classes that extend the handlebar class. Mountain bike…

Contents