This project implements the Builder Pattern in Java for creating Car objects. The implementation demonstrates Clean Code principles with small, focused methods, descriptive naming, and proper validation.
- Immutable Car class with final fields and private constructor
- Builder pattern with fluent interface for object construction
- Input validation with meaningful error messages
- Clean Code principles applied throughout the implementation
- Comprehensive examples demonstrating usage and error handling
assignment/
├── src/main/java/com/example/car/
│ ├── Car.java # Main Car class with Builder pattern
│ └── App.java # Example usage and demonstrations
├── uml/
│ └── class_diagram.puml # PlantUML class diagram
├── README.md # This file
└── report.docx # Project report (to be created)
- Java Development Kit (JDK) 8 or higher
- Java compiler (
javac) and runtime (java)
# Navigate to the project root
cd assignment
# Compile the Java files
javac -d . src/main/java/com/example/car/*.java# Run the example application
java com.example.car.AppCar sportsCar = new Car.Builder()
.setSeats(2)
.setEngineType("V8 Turbo")
.setGPS(true)
.setTripComputer(true)
.build();
System.out.println(sportsCar);
// Output: Car{seats=2, engine='V8 Turbo', GPS=true, TripComputer=true}try {
Car invalidCar = new Car.Builder()
.setSeats(0) // Invalid: seats must be > 0
.setEngineType("V6")
.build();
} catch (IllegalStateException e) {
System.out.println("Error: " + e.getMessage());
// Output: Error: Seats must be greater than 0, got: 0
}// Family car
Car familyCar = new Car.Builder()
.setSeats(7)
.setEngineType("V6")
.setGPS(true)
.setTripComputer(false)
.build();
// Luxury car
Car luxuryCar = new Car.Builder()
.setSeats(4)
.setEngineType("V12 Twin Turbo")
.setGPS(true)
.setTripComputer(true)
.build();
// Basic car
Car basicCar = new Car.Builder()
.setSeats(5)
.setEngineType("4-Cylinder")
.setGPS(false)
.setTripComputer(false)
.build();The class diagram can be viewed using PlantUML:
- File:
uml/class_diagram.puml - Online Viewer: PlantUML Online Server
- VS Code Extension: PlantUML extension for VS Code
- Small Functions: Each method is focused and under 20 lines
- Single Responsibility: Each method has one clear purpose
- Descriptive Names: Method and variable names clearly express intent
- No Flag Arguments: Boolean parameters are avoided in favor of explicit methods
- Validation: Input validation is separated into dedicated methods
- Immutability: Car objects are immutable once created
- Error Handling: Meaningful error messages with context
feat: implement Car class with Builder patternfeat: add input validation and error handlingfeat: create App.java with usage examplesdocs: add UML class diagramdocs: create comprehensive READMErefactor: apply Clean Code principlestest: add error handling demonstrations
Student Name: Sergej Balakarev
Group: SE-2404
Course: Software Design Patterns
Date: 14.09.25