OOP Design

10 classic interview prompts. Click a title to expand the canonical class breakdown.

Design an object-oriented parking lot with multiple levels, multiple spot sizes (motorcycle, compact, large), and dynamic pricing. A ticket is issued on entry and used to compute the bill on exit.

Classes you would define
ParkingLot: Top-level aggregate that owns Levels, accepts park/unpark requests, and delegates spot assignment.
Level: Owns a collection of ParkingSpots and tracks availability counters per size for O(1) lookup.
ParkingSpot: A single physical spot with a size and current occupant; knows whether a given vehicle fits.
Vehicle (abstract) / Motorcycle, Car, Truck: Encodes size and license plate; subclasses exist mainly so spot-fit logic stays polymorphic.
Full breakdown and Java sketch

Design a library system that tracks books, members, check-outs, holds, and fines. A single title may have many physical copies; members can place holds when all copies are checked out.

Classes you would define
Book: Logical title-level record (ISBN, author, subject); does not represent a physical item.
BookCopy: A physical, checkoutable instance of a Book with a barcode, location, and current status.
Member: Library patron with status, current loans, holds, and outstanding fines.
Loan: Open transaction linking a BookCopy to a Member with checkout date and due date.
Full breakdown and Java sketch

Design an elevator control system for a building with N elevators and F floors. Riders press hall buttons on each floor (up/down) and car buttons inside each elevator. The system must dispatch efficiently and serve every request.

Classes you would define
Building: Owns the set of Elevators and Floors and routes hall calls into the Dispatcher.
Elevator: Single car with current floor, direction, capacity, and an ordered set of pending stops.
Floor: Hall call buttons (up/down) and the up/down indicators; emits HallRequest events.
Request (HallRequest, CarRequest): Value object representing a single ask; distinguishing hall vs car matters for scheduling.
Full breakdown and Java sketch

Design a vending machine that holds inventory across slots, accepts coins and bills, dispenses a product, and returns correct change. Model the full transaction lifecycle including cancellation.

Classes you would define
VendingMachine: Top-level facade exposing insert, select, cancel, and dispense; owns the current transaction state.
Inventory: Maps slot codes to (Product, count); enforces decrement-on-dispense and supports restock.
Product: Immutable product descriptor: name, price, slot affinity.
CashRegister: Tracks denomination counts; computes whether a given change amount is makeable and produces the payout.
Full breakdown and Java sketch

Design an ATM that authenticates a cardholder, then supports balance inquiry, withdrawal, deposit, and transfer. Enforce per-account daily withdrawal limits and machine cash limits.

Classes you would define
ATM: Hardware-facing facade coordinating card reader, keypad, cash dispenser, and deposit slot.
Session: Authenticated user session bound to a Card; expires on logout, timeout, or completion.
Card: Holds card number and links to one or more Accounts; carries per-card daily limits.
Account: Bank account with balance and daily-withdrawal accumulator; mutated only via Transactions.
Full breakdown and Java sketch

Design a chess game: model the board, pieces, legal-move generation, turn order, and game-end detection (checkmate, stalemate, draws). Focus on a piece hierarchy that's easy to extend.

Classes you would define
Game: Owns Board, two Players, move history, and game state; the entry point for makeMove.
Board: 8x8 grid of Squares; provides piece lookup, move application, and snapshotting for undo.
Square: A coordinate that may hold a Piece; thin wrapper that simplifies move generation.
Piece (abstract): King, Queen, Rook, Bishop, Knight, Pawn: Each subclass generates its candidate moves from a position; legality is filtered by Board.
Full breakdown and Java sketch

Design an Amazon-style online bookstore: catalog, search, cart, checkout, orders, and payment. Focus on the domain model and how state moves through the order lifecycle.

Classes you would define
Catalog: Searchable index of Books with price and availability lookups; abstracts the search backend.
Book: Product entity: ISBN, title, author, price, and stock pointer.
User: Account identity holding addresses, payment methods, and order history references.
Cart: Per-user mutable collection of CartItems; computes subtotal and survives across sessions.
Full breakdown and Java sketch

Design a hotel reservation system that supports searching available rooms by date range and room type, booking with pricing, modifying or cancelling reservations, and check-in/check-out at the property.

Classes you would define
Hotel: Owns Rooms and exposes search/book operations against its inventory.
Room: Physical room with type, number, and floor; holds long-lived attributes, not pricing.
RoomType: Class of room (Standard, Suite) used for search and base pricing; many Rooms per type.
Reservation: Guest's booking covering a date range and a RoomType, with a price quote and status.
Full breakdown and Java sketch

Design an in-process pub/sub system: publishers post messages to topics, and subscribers receive messages from topics they subscribe to. Support multiple subscribers per topic, retention, and delivery guarantees.

Classes you would define
Broker: Top-level registry of Topics and Subscriptions; the entry point for publish and subscribe.
Topic: Named channel that owns its message log and the set of Subscriptions reading from it.
Message: Immutable record with payload, headers, offset, and timestamp.
Subscription: Per-subscriber state on a Topic: handler reference, current offset, ack state.
Full breakdown and Java sketch

Design a movie ticket booking system: theaters with multiple screens, movies showing at scheduled times, seat selection with temporary holds during checkout, and payment that confirms the booking.

Classes you would define
Movie: Film catalog entry: title, duration, rating, language; independent of any showing.
Theater: Physical venue that owns one or more Screens and a location.
Screen: Auditorium with a fixed seat layout; hosts Shows over time.
Show: A specific Movie on a specific Screen at a specific time; owns the per-seat availability for that showing.
Full breakdown and Java sketch