Hierarchy of the project:
- Interfaces:
EngineBehavior: Describes the behavior of the car engine.
CarFactory: Creates different types of cars.
TrackFactory: Creates different types of tracks.
NOSFactory: Creates different types of NOS (Nitrous Oxide System).
- Concrete Classes:
- Engine Behaviors:
V6Engine: Represents a V6 engine behavior.
V8Engine: Represents a V8 engine behavior.
V12Engine: Represents a V12 engine behavior.
- Cars:
Car: Abstract class representing a basic car.
ToyotaGR86, SubaruBRZ, PorscheBoxster, Ferrari812: Concrete car classes.
AlpineTurbocharger, CumminsTurbocharger, HoneywellTurbocharger: Concrete turbocharger classes (decorators).
- Turbochargers:
Turbocharger: Abstract class for turbochargers.
AlpineTurbocharger, CumminsTurbocharger, HoneywellTurbocharger: Concrete turbocharger classes (decorators).
- Factories:
CoupeCarFactory: Factory for creating coupe cars.
RoadsterCarFactory: Factory for creating roadster cars.
TrackFactoryImpl: Factory for creating tracks.
- Tracks:
Track: Abstract class representing a basic track.
BlueMoonBaySpeedway, BBRaceway, CircuitDeSpa: Concrete track classes.
- Race Types:
RaceTypeFactory: Abstract factory for creating different types of races.
SprintRaceFactory, CircuitRaceFactory: Factories for creating sprint and circuit races.
- Rii:
Rii: Main class containing the main method, where the game is initialized and played.
- Usage:
- The
Rii class uses the factories to dynamically create cars, tracks, and race types based on user input.
- Decorators are used to add turbochargers to the selected cars dynamically.
- The strategy pattern is used with different engine behaviors.
- Various patterns work together to provide a flexible and extensible design for the racing game.
Design Pattern used in the project:
- Abstract Factory Pattern:
- Usage: Implemented with
CarFactory, TrackFactory, and NOSFactory interfaces, and their corresponding concrete factory classes (CoupeCarFactory, RoadsterCarFactory, TrackFactoryImpl).
- Purpose: Allows the creation of families of related or dependent objects without specifying their concrete classes.
- Decorator Pattern:
- Usage: Implemented with
Turbocharger as the abstract decorator class and AlpineTurbocharger, CumminsTurbocharger, HoneywellTurbocharger as concrete decorators.
- Purpose: Adds responsibilities (in this case, turbochargers) to objects dynamically.
- Factory Method Pattern:
- Usage: Implemented with the
createCar and createTrack methods in CarFactory and TrackFactory interfaces, respectively.
- Purpose: Defines an interface for creating an object but leaves the choice of its type to the subclasses, creating instances of classes derived from an interface.
- Strategy Pattern:
- Usage: Implemented with various engine classes (
V6Engine, V8Engine, V12Engine) that implement the EngineBehavior interface.
- Purpose: Defines a family of algorithms, encapsulates each algorithm, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
- Factory Pattern:
- Usage: Implemented with
SprintRaceFactory and CircuitRaceFactory as factories for creating different types of races.
- Purpose: Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
- Singleton Pattern:
- Usage: To create
Player
- Purpose: Ensures a class has only one instance and provides a global point to this instance.