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 extensible factories

Implement extensible factories - Java Tutorial

From the course: Java Design Patterns: Creational

Start my 1-month free trial

Implement extensible factories

- [Instructor] In this example, the bike builder application has been rewritten to be more extensible. It is now easier to add bike parts to the application without having to alter code in several different places. The first difference is that a new class has been added. This is an abstract class called BikePart. It declares a single abstract method called getDescription. This class is extended by the Tire class and the Handlebar class. Then, the bike specific classes still extend these. For example, the MountainBikeHandlebar class extends the Handlebar class and the Handlebar class extends the BikePart class. So all of the specific BikePart classes, MountainBikeHandlebar, RoadBikeHandlebar, MountainBikeTire and RoadBikeTire, all extend classes that extend BikePart. The reason they all extend the same abstract class is because this then means that the create methods can be combined into one. Inside the BikeFactory class, there is now only a single method. This avoids the necessity to…

Contents