How snj07/parking-lot-system works
Project type and purpose
• This is a standalone, open-source, command-line Parking Lot system written in Java.
• It reads parking commands (park, leave, status, etc.) from a file or console, processes them in memory, and outputs results.
File structure
• Top level: Gradle build files, Main.java, JAR, tests.
• src/main/java packages reflect layers:
• constant (static values/messages)
• controller (input ingestion + command execution)
• dao (data handling; in-memory implementation)
• model (domain objects: Car, Vehicle, Driver)
• service (business logic)
• strategy (parking slot allocation strategy)
• observers (publish-subscribe for output collection)
• utils (file reading)
• src/main/resources contains sample input files.
• src/test/java has unit tests.
README for additional insights
• Tech stack: Java 8+, Gradle wrapper, JUnit 5.
• No external DB—DAO uses in-memory structures.
• Commands described for running with Gradle or JAR.
• High-level structure matches package layout.
Main components & relationships
a. Components:
• External: Input Source (console or file)
• InputController (ConsoleInputController or FileInputController)
• CommandController (parses commands via CommandPatternController)
• Service layer (ParkingLotService)
• Strategy (NearestSlotParkingStrategy implementing ParkingStrategy)
• DAO (ParkingLotDataHandler interface with InMemoryParkingLotHandler)
• Model objects (ParkingLot, Slot, Vehicle, Driver)
• Observers (CommandObservable + console/string output observers)
• Utility (FileUtils)
b. Interactions / Data Flow:
1. Main → selects InputController
2. InputController → reads raw commands → passes to CommandController
3. CommandController → validates against constants → invokes Service
4. Service → employs Strategy to pick slot → calls DAO to create/update models
5. DAO → updates in-memory data structure
6. Service/Controller → notifies registered Observers with results
7. Observers → produce output to console or collect strings
c. Architectural patterns & principles:
• MVC-style separation: controllers ↔ service ↔ data
• Strategy pattern for parking slot allocation
• Observer pattern for output capture
• DAO abstraction for data operations
• Single Responsibility: constants, utils, exceptions isolated
d. Key technologies & frameworks:
• Java 8+
• Gradle wrapper (build & run)
• JUnit 5 for unit tests
Detailed breakdown
• Both controllers implementing a common InputController interface.
• CommandPatternController calls ParkingLotService (implements IService).
• Inside ParkingLotService, annotate usage of NearestSlotParkingStrategy.
• ParkingLotService calls ParkingLotDataHandler (interface) → InMemoryParkingLotHandler.
• InMemoryParkingLotHandler updates Model objects (ParkingLot, Slot, Vehicle, Driver).
• Service/Controller register observers with CommandObservable → CommandConsoleOutputObserver and CommandStringOutputStoreObserver.
• FileUtils sits beside FileInputController to show its helper role.
• Constants, Enums, Exception packages can be drawn as supporting libraries around all components.