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:

  1. Review the provided Car Builder System application. This application currently supports creating cars with an engine, wheels, and a color.

  2. Add a new feature to the car: Interior. This will require creating a new setInterior(String interior) method in the Car class and updating the CarBuilder interface and CarBuilderImpl class.

    • The Interior attribute should represent the type of the car's interior, such as "Leather" or "Fabric".

  3. Create a new CarDirector subclass: LuxuryCarDirector. This class should override the build() method to create a car with "V12" engine, "20 inch" wheels, "Black" color, and "Leather" interior.

  4. Update the main() method in your client code to create a regular car and a luxury car using the appropriate directors.

  5. 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!