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.

Dealing with extensible factories

Dealing with extensible factories - Java Tutorial

From the course: Java Design Patterns: Creational

Start my 1-month free trial

Dealing with extensible factories

- [Instructor] In this example there is an application that builds bikes and that uses the abstract factory pattern. However, as the application gets more complex, the abstract factory becomes more complex too. The Factory Creator class has a method called createFactory and this takes the type of bike needed as a parameter. If mountain bike is passed in, it will return a mountain bike factory that can create mountain bike parts. And if road bike is passed in, it will return a road bike factory that can create road bike parts. These factories both extend an abstract class called BikeFactory. If I open the BikeFactory class, it has two methods called createTire and createHandlebar. Obviously, in reality, more than just tires and a handlebar are needed to make a bike. There will also need to be brakes, gears, a saddle, pedals, and so on. There might also be other types of bike that need to be created besides mountain bikes and road bikes. A more complete version of the application might…

Contents