Builder Pattern Lab 1
Lab: Enhancing the Car Builder System
Objective:
In this lab, you will extend the provided Car Builder System application by adding new features to the car.
Instructions:
Review the provided Car Builder System application. This application currently supports creating cars with an engine, wheels, and a color.
Add a new feature to the car:
Interior
. This will require creating a newsetInterior(String interior)
method in theCar
class and updating theCarBuilder
interface andCarBuilderImpl
class.The
Interior
attribute should represent the type of the car's interior, such as "Leather" or "Fabric".
Create a new
CarDirector
subclass:LuxuryCarDirector
. This class should override thebuild()
method to create a car with "V12" engine, "20 inch" wheels, "Black" color, and "Leather" interior.Update the
main()
method in your client code to create a regular car and a luxury car using the appropriate directors.Test your application to ensure it behaves as expected. A regular car should have a "V8" engine, "18 inch" wheels, "Red" color, and null interior. A luxury car should have a "V12" engine, "20 inch" wheels, "Black" color, and "Leather" interior.
Tips:
The Builder pattern separates the construction of an object from its representation. This allows the same construction process to create different representations.
Submission:
You should submit your completed Java files for Car
, CarBuilder
, CarBuilderImpl
, CarDirector
, LuxuryCarDirector
, and Main
.
Remember, the goal of this lab is to understand the Builder pattern and how it can be used to construct complex objects step by step. Good luck!