Sample Object-Oriented Design Interview Questions and Answers
1. Design a Parking Lot System
Question: Design a parking lot with multiple levels, each with multiple parking spots of different sizes (small, medium, large). Vehicles can be motorcycles, cars, or buses.
Answer:
Key Classes:
-
ParkingLot -
Level -
ParkingSpot -
Vehicle(abstract)-
Car -
Motorcycle -
Bus
-
Design Approach:
-
Use inheritance for vehicle types.
-
Each
Levelcontains multipleParkingSpots. -
ParkingSpothas a type (SMALL,MEDIUM,LARGE) and availability status. -
Vehiclehas methodcanFitInSpot(ParkingSpot).
Design Considerations:
-
A
Busneeds 5 contiguousLARGEspots on the same level. -
Motorcyclefits in any spot,Carin medium or large. -
Use Strategy or Factory pattern for flexible spot assignment logic.
2. Design an Online Book Reader System
Question: Design a system for an online book reader. Users can read books, bookmark pages, and make notes.
Answer:
Key Classes:
-
OnlineReaderSystem -
User -
Book -
Library -
Bookmark -
Note -
Display
Design Approach:
-
Libraryhandles search and management of books. -
Usercan interact withBook, setBookmark, and createNote. -
Displayclass shows book content, current page, notes, etc.
OOP Principles Used:
-
Encapsulation: Each class maintains its own state.
-
Composition: A
Userhas multipleBookmarksandNotes.
3. Design a Hotel Management System
Question: Design a hotel reservation system to handle bookings, room availability, check-in/check-out, and billing.
Answer:
Key Classes:
-
Hotel -
Room -
Reservation -
Customer -
Invoice -
Payment -
Receptionist/Admin/Guest(User Roles)
Design Considerations:
-
Roomhas type, price, and availability. -
Reservationincludes booking dates and room info. -
Use the State pattern for room status:
Available,Reserved,Occupied,UnderMaintenance. -
Billing is associated with the reservation and finalized during checkout.
Additional Components:
-
Notification service (e.g., SMS/email)
-
Calendar integration for room availability
4. Design a Ride-Sharing App (like Uber)
Question: Design the backend for a ride-hailing app including driver, passenger, trip management, and payments.
Answer:
Key Classes:
-
User(abstract)-
Driver -
Passenger
-
-
Trip -
Vehicle -
Location -
Payment -
RideService
Design Concepts:
-
Observer pattern for location tracking and status updates.
-
Strategy pattern for different pricing models (e.g., surge pricing).
-
Each
Tripcontains origin, destination, driver, passenger, status, and cost. -
Vehicle types can be matched based on user preference and availability.
5. Design a Social Media News Feed
Question: Design the news feed system for a social media app. Show personalized, recent posts from friends and followed users.
Answer:
Key Classes:
-
User -
Post -
Feed -
Friendship -
NewsFeedService
Key Features:
-
Posts have timestamps, privacy settings, and content types (text, image, video).
-
Use a priority queue or min-heap to merge posts from multiple sources efficiently.
-
Feed ranking algorithm based on relevance (likes, time decay, engagement).
Patterns & Principles:
-
Dependency Injection for personalization service.
-
Strategy pattern for ranking algorithm.
-
Caching and background feed prefetching for performance.
6. Design a File System
Question: Design a simplified in-memory file system with support for directories and files.
Answer:
Key Classes:
-
FileSystem -
Directory -
File -
Node(abstract with name, path)
Approach:
-
Composite pattern for
DirectoryandFileunderNode. -
Use a tree structure to represent hierarchy.
-
Add operations:
mkdir,addFile,delete,move,list.
Advanced Considerations:
-
Permissions and ownership
-
File metadata (size, timestamps)
-
Path resolution and symbolic links
7. Design an ATM System
Question: Design an ATM system including card insertion, PIN validation, transactions, and cash dispensing.
Answer:
Key Classes:
-
ATM -
Bank -
Account -
Card -
Transaction(abstract)-
Withdrawal -
Deposit -
BalanceInquiry
-
-
CashDispenser -
Keypad,Screen,Printer
Design Focus:
-
Use State pattern for ATM states:
Idle,CardInserted,Authenticated,TransactionInProgress. -
Strategy pattern for different transaction types.
-
Card validation routed through the bank, which holds account data.
8. Design a Chess Game
Question: Design an object-oriented chess game that can be played between two users.
Answer:
Key Classes:
-
ChessGame -
Board -
Player -
Piece(abstract)-
Pawn,Knight,Bishop,Rook,Queen,King
-
-
Move -
Cell
Design Details:
-
Use Factory pattern for initializing pieces.
-
Each
Piecehas methodisValidMove(Position from, Position to, Board board). -
Enforce game rules like check/checkmate, castling, en passant using Rule classes.
Additional Components:
-
Game history tracking using a list of
Moves -
Observer pattern for UI updates
9. Design a Movie Ticket Booking System
Question: Design a system for booking movie tickets in multiple theaters.
Answer:
Key Classes:
-
Movie -
Show -
Theater -
Seat -
Booking -
User -
Payment
Design Highlights:
-
Each
Theaterhas multipleShows for aMovie. -
Seathas status:Available,Booked,Blocked. -
Concurrency handling for seat booking using locking or optimistic concurrency.
Additional Features:
-
Search by location, movie, and showtime
-
Loyalty program integration
-
Cancellation and refund policy
10. Design a Notification System
Question: Design a notification system supporting multiple channels: Email, SMS, Push.
Answer:
Key Classes:
-
Notification -
NotificationService -
NotificationChannel(interface)-
EmailChannel -
SMSChannel -
PushChannel
-
-
UserPreference
Design Principles:
-
Use Strategy pattern to send via different channels.
-
Observer pattern for subscription-based updates.
-
UserPreferencedetermines preferred channel(s).
Scalability:
-
Asynchronous delivery via message queues
-
Retry and fallback mechanisms
These sample object-oriented design interview questions and answers showcase how to approach problem decomposition, apply design principles, and use design patterns effectively. Mastering such cases will significantly improve your performance in software engineering interviews.