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
ParkingLotTop-level aggregate that owns Levels, accepts park/unpark requests, and delegates spot assignment.
LevelOwns a collection of ParkingSpots and tracks availability counters per size for O(1) lookup.
ParkingSpotA single physical spot with a size and current occupant; knows whether a given vehicle fits.
Vehicle (abstract) / Motorcycle, Car, TruckEncodes 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
BookLogical title-level record (ISBN, author, subject); does not represent a physical item.
BookCopyA physical, checkoutable instance of a Book with a barcode, location, and current status.
MemberLibrary patron with status, current loans, holds, and outstanding fines.
LoanOpen 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
BuildingOwns the set of Elevators and Floors and routes hall calls into the Dispatcher.
ElevatorSingle car with current floor, direction, capacity, and an ordered set of pending stops.
FloorHall 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
VendingMachineTop-level facade exposing insert, select, cancel, and dispense; owns the current transaction state.
InventoryMaps slot codes to (Product, count); enforces decrement-on-dispense and supports restock.
ProductImmutable product descriptor: name, price, slot affinity.
CashRegisterTracks 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
ATMHardware-facing facade coordinating card reader, keypad, cash dispenser, and deposit slot.
SessionAuthenticated user session bound to a Card; expires on logout, timeout, or completion.
CardHolds card number and links to one or more Accounts; carries per-card daily limits.
AccountBank 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
GameOwns Board, two Players, move history, and game state; the entry point for makeMove.
Board8x8 grid of Squares; provides piece lookup, move application, and snapshotting for undo.
SquareA coordinate that may hold a Piece; thin wrapper that simplifies move generation.
Piece (abstract) — King, Queen, Rook, Bishop, Knight, PawnEach 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
CatalogSearchable index of Books with price and availability lookups; abstracts the search backend.
BookProduct entity: ISBN, title, author, price, and stock pointer.
UserAccount identity holding addresses, payment methods, and order history references.
CartPer-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
HotelOwns Rooms and exposes search/book operations against its inventory.
RoomPhysical room with type, number, and floor; holds long-lived attributes, not pricing.
RoomTypeClass of room (Standard, Suite) used for search and base pricing; many Rooms per type.
ReservationGuest'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
BrokerTop-level registry of Topics and Subscriptions; the entry point for publish and subscribe.
TopicNamed channel that owns its message log and the set of Subscriptions reading from it.
MessageImmutable record with payload, headers, offset, and timestamp.
SubscriptionPer-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
MovieFilm catalog entry: title, duration, rating, language; independent of any showing.
TheaterPhysical venue that owns one or more Screens and a location.
ScreenAuditorium with a fixed seat layout; hosts Shows over time.
ShowA specific Movie on a specific Screen at a specific time; owns the per-seat availability for that showing.
Full breakdown and Java sketch