How to Approach an Object-Oriented Design Problem

Anshul Jain
3 min readMay 14, 2022
Photo by Amélie Mourichon on Unsplash

Object-Oriented Design questions may require a candidate to sketch out the classes and methods to implement technical problems or real-life objects

These questions are about demonstrating that you understand how to create elegant, maintainable, object-oriented code

Poor performance on this type of question may raise serious red flags.

Step 1: Handle Ambiguity

OOD questions are often intentionally vague in order to test whether you will make assumptions or if you will ask clarifying questions.

After all, a developer who just codes something without understanding what one is expected to create wastes the company’s resources, and time and may cause severe issues in future.

When being asked about an Object-Oriented Design question, you should inquire who will use it and how they are going to use it.
Depending on the question you may go through “six Ws” ( Who, What, Where, When, How, Why)

For example, suppose you were asked to OOD for a coffee maker

  • Your coffee maker might be an industrial machine used in a massive restaurant, servicing hundreds of customers per hour, and making ten different kinds of coffee products.
  • Or it might be a simple machine designed to be used by an individual for just simple black coffee.
  • These use cases will significantly impact your design.

Step 2: Define Core Objects

Now that we understand what we are designing, we should identify what are the core objects in the system.

For example, if we are asked to do Object-Oriented Design for a restaurant. Our core objects might be things like Table, Order, Guest, Meal, Employee, Server, Host, Party etc.

Step 3: Analyse Relationships between objects

After going through steps 1 and 2, now we know what are we designing and what are the core objects of the system.

It is time to identify the relationships between objects by answering

  • Which Objects are members of which other objects?
  • Do any objects inherit from any other object?
  • Is the relationship one-to-many or many-to-many?

For example, for the restaurant question(of step 2), we may come up with the following design

  • Party should have an array of Guests
  • Server and Host inherit from Employee
  • Each Table has one Party, but each Party can have multiple Table
  • There is only one host for the Restaurant

Be very careful, here you can make incorrect assumptions. You should talk to your interviewer about how general-purpose your design should be.

Step 4: Investigate Actions

At this point, we have the basic outline of your object-oriented design. What remains is to identify key actions that the objects will take and how they relate to each other.

For example

  • Party Walks into the Restaurant
  • Guest Requests a Table from the Host.
  • The Host LooksUp the Reservation and if it exists, Assigns the Party to a Table
  • When a Party Leaves the Table is Freed

You may find that you have missed some objects and you will need to update your design accordingly.

GitHub | LinkedIn

Further, read Design Patterns

--

--

Anshul Jain

Software Engineer | Microsoft Azure | Machine Learning