This document provides comprehensive documentation for the object-oriented design patterns and relationships across all case studies in the "Grokking the Object Oriented Design Interview" project.
The object diagram (object-diagram.puml) visualizes the class structures, relationships, and design patterns used across 8 major system designs:
- Library Management System
- Parking Lot System
- Online Shopping System
- Chess Game System
- ATM System
- Hotel Management System
- Airline Management System
- Movie Ticket Booking System
- Visit PlantUML Online Editor
- Copy the contents of
object-diagram.puml - Paste into the editor to view the rendered diagram
- Install the "PlantUML" extension by jebbs
- Open
object-diagram.puml - Press
Alt+Dto preview the diagram
# Install PlantUML
# Then run:
java -jar plantuml.jar object-diagram.pumlCore Classes:
Account(Abstract) →Librarian,MemberBook(Abstract) →BookItemBookReservation,BookLending,FineRack
Key Relationships:
- Inheritance: Account is extended by Librarian and Member
- Composition: BookItem is placed at a Rack
- Association: Member interacts with BookReservation, BookLending, and Fine
Design Patterns:
- Template Method Pattern: Account class provides template for different account types
- Factory Pattern: Book creation can be handled through factory methods
Key Features:
- Members can checkout, return, and renew books
- Librarians can add books and manage members
- Fine calculation for overdue books
- Book reservation system
Core Classes:
ParkingLot(Singleton)ParkingFloor,ParkingSpot(Abstract)Vehicle(Abstract) →Car,Van,Truck,Motorbike,ElectricCarParkingTicket,EntrancePanel,ExitPanel
Key Relationships:
- Singleton: ParkingLot ensures single instance
- Inheritance: Different vehicle types and parking spot types
- Composition: ParkingLot contains multiple ParkingFloors, each with multiple ParkingSpots
Design Patterns:
- Singleton Pattern: ParkingLot class (only one instance in the system)
- Strategy Pattern: Different parking spot allocation strategies
- Factory Pattern: Vehicle and ParkingSpot creation
Key Features:
- Multi-floor parking management
- Different spot types (Compact, Large, Motorbike, Electric)
- Ticket generation and payment processing
- Real-time spot availability tracking
Core Classes:
ShoppingAccountCustomer(Abstract) →Guest,ShoppingMemberShoppingCart,Item,ProductOrder,OrderLog,Shipment
Key Relationships:
- Inheritance: Customer hierarchy (Guest vs Member)
- Composition: ShoppingCart contains Items, Order contains OrderLogs
- Association: Order linked to Shipment
Design Patterns:
- State Pattern: Order status management
- Observer Pattern: Order status notifications
- Composite Pattern: Shopping cart with multiple items
Key Features:
- Guest and member shopping capabilities
- Shopping cart management
- Order processing and tracking
- Product catalog and search
- Shipment tracking
Core Classes:
ChessGame,ChessBoardPiece(Abstract) →King,Queen,Rook,Bishop,Knight,PawnPosition,MoveCommand,Player
Key Relationships:
- Inheritance: All chess pieces inherit from Piece
- Composition: ChessBoard contains multiple Pieces
- Association: MoveCommand operates on Positions
Design Patterns:
- Strategy Pattern: Each piece has different movement strategy
- Command Pattern: MoveCommand encapsulates move operations
- Template Method Pattern: Piece class provides template for move validation
Key Features:
- Complete chess game logic
- Move validation for each piece type
- Check and checkmate detection
- Turn-based gameplay
- Position tracking
Core Classes:
ATM,BankBankAccount(Abstract) →SavingsAccount,CheckingAccountTransaction(Abstract) →BalanceInquiry,Deposit,Withdraw,TransferCustomer,Card
Key Relationships:
- Inheritance: Different account types and transaction types
- Association: Customer has Card and BankAccount
- Composition: Bank contains multiple BankAccounts
Design Patterns:
- Command Pattern: Transaction hierarchy
- State Pattern: Transaction status management
- Proxy Pattern: ATM acts as proxy to Bank
Key Features:
- Multiple transaction types
- Account management (Savings/Checking)
- Card-based authentication
- Balance inquiry and fund transfers
- Cash withdrawal and deposit
Core Classes:
Hotel,HotelLocationRoom(Abstract) →StandardRoom,DeluxeRoom,FamilySuite,BusinessSuiteRoomBooking,RoomChargeHotelGuest,ReceptionistAmenity,KitchenService
Key Relationships:
- Inheritance: Different room types
- Composition: Hotel contains HotelLocations, which contain Rooms
- Association: RoomBooking links Guest to Room
Design Patterns:
- Factory Pattern: Room creation based on type
- Observer Pattern: Booking status notifications
- Decorator Pattern: Room amenities and services
Key Features:
- Multi-location hotel management
- Different room types and pricing
- Booking and reservation system
- Guest management
- Room services and amenities
- Invoice generation
Core Classes:
Airline,Aircraft,SeatFlight,FlightInstanceFlightReservation,ItineraryAirport,Passenger
Key Relationships:
- Composition: Airline contains Aircraft, Aircraft contains Seats
- Association: FlightInstance links to Flight and Aircraft
- Aggregation: Itinerary contains multiple FlightReservations
Design Patterns:
- Composite Pattern: Itinerary with multiple reservations
- Factory Pattern: Flight and reservation creation
- State Pattern: Flight status management
Key Features:
- Flight scheduling and management
- Seat reservation system
- Multi-leg itinerary support
- Passenger management
- Airport and aircraft tracking
- Flight status updates
Core Classes:
Cinema,CinemaHall,CinemaHallSeatShow,MovieMovieBooking,ShowSeatPayment
Key Relationships:
- Composition: Cinema contains CinemaHalls, CinemaHall contains Seats
- Association: Show links Movie to CinemaHall
- Aggregation: MovieBooking contains ShowSeats
Design Patterns:
- Factory Pattern: Show and booking creation
- State Pattern: Seat and booking status management
- Observer Pattern: Booking notifications
Key Features:
- Multi-hall cinema management
- Show scheduling
- Seat selection and booking
- Real-time seat availability
- Payment processing
- Booking confirmation
Used extensively across all systems to create specialized classes from general ones:
- Account → Librarian, Member
- Vehicle → Car, Van, Truck
- Customer → Guest, Member
- Piece → King, Queen, Rook, etc.
Strong ownership relationships:
- ParkingLot has ParkingFloors
- ShoppingCart has Items
- ChessBoard has Pieces
- Cinema has CinemaHalls
Weaker relationships between objects:
- Member uses BookReservation
- Customer places Order
- FlightReservation links to Passenger
ParkingLot: Ensures only one parking lot instance exists
- Chess pieces: Each piece has different movement strategy
- Parking spot allocation: Different strategies for different vehicle types
- ATM transactions: Each transaction type encapsulates an action
- Chess moves: MoveCommand encapsulates move operations
- Object creation across all systems (Books, Vehicles, Rooms, etc.)
- Order status management
- Booking status management
- Flight status management
- Notification systems for bookings and reservations
The diagram includes a "Common Elements" package with shared classes:
- Person: Basic person information (name, address, email, phone)
- Address: Standard address structure
- AccountStatus: Enum for account states
- PaymentStatus: Enum for payment states
These are used across multiple systems to maintain consistency.
<|--: Inheritance (extends)*--: Composition (strong ownership)-->: Association (uses)o--: Aggregation (weak ownership)
Single Responsibility Principle (SRP)
- Each class has a single, well-defined purpose
- Example:
BookLendinghandles only lending operations
Open/Closed Principle (OCP)
- Classes are open for extension but closed for modification
- Example: Adding new vehicle types doesn't require modifying existing code
Liskov Substitution Principle (LSP)
- Derived classes can substitute base classes
- Example: Any
Vehiclesubclass can be used whereVehicleis expected
Interface Segregation Principle (ISP)
- Clients aren't forced to depend on interfaces they don't use
- Example: Different account types have specific methods
Dependency Inversion Principle (DIP)
- Depend on abstractions, not concretions
- Example: Abstract
Account,Vehicle,Piececlasses
- All classes use private attributes (indicated by
__prefix in Python) - Public methods provide controlled access
- Abstract base classes define common interfaces
- Concrete classes implement specific behaviors
- Different implementations of common interfaces
- Example: Different chess pieces implement
canMove()differently
When discussing these designs in interviews:
- Start with high-level architecture: Explain the main components and their relationships
- Identify key patterns: Point out which design patterns are used and why
- Discuss trade-offs: Explain why certain design decisions were made
- Consider scalability: How would the design handle growth?
- Address edge cases: What happens in error scenarios?
To add new systems or modify existing ones:
- Follow the existing package structure
- Use consistent naming conventions
- Apply appropriate design patterns
- Maintain clear relationships between classes
- Add notes for complex patterns or behaviors
- PlantUML Documentation: https://plantuml.com/
- Design Patterns: "Design Patterns: Elements of Reusable Object-Oriented Software" by Gang of Four
- UML Basics: https://www.uml-diagrams.org/
- This diagram represents the class structure (static view) of the systems
- For dynamic behavior (sequence of operations), refer to sequence diagrams in the project
- The diagram is simplified for clarity; actual implementations may have additional helper classes
- All code examples in the project are in Python but concepts apply to any OOP language
Last Updated: 2025-11-03 Version: 1.0 Author: Generated for Grokking the Object Oriented Design Interview Project