Top 5 Object Oriented Analysis and Design Interview Questions for Programmers, Software Engineers

Testing the design skill of a candidate is quite common in programming job interviews. Questions like, how do you design a vending machine or a traffic control system are very popular in object-oriented programming language interviews, like Java and C++. Designing a software System requires good experience and knowledge of tools of object-oriented design and analysis. You should not only be good at OOP fundamentals like Abstraction, Inheritance, Polymorphism, Encapsulation, Coupling, Cohesion, Association, Aggregation, or Composition but also on several crucial object-oriented design principles like SOLID Principles of Object-Oriented Design, which is the building block for writing flexible and maintainable code.

Good knowledge of when to use a class over an interface is also essential for designing a maintainable software or Java application. Now, the questions are how do you develop such skills? You need to practice and practice hard. This is why I am sharing some frequently asked object-oriented design questions from Java programming interviews here.

Anyway, Software design has many facets, object-oriented system design is just one of them. Sometimes, you may be asked to design a database for an e-commerce application. Database design is totally different than object-oriented design.

There you need to follow rules of flexible and maintainable designs and Normalization. You need to make sure your tables are in 3rd normal form, and there is a nice balance between duplication of data and the easiness of querying the data.

Btw, this tutorial is about object-oriented system design, and I'll share questions on that. I'll write about SQL and database design sometime later to give you more information and some practice questions as well.

Another thing to note is that now there are a couple of excellent courses available online, which can help you with this challenging aspect of coding interviews. I have tried the Grokking System Design Interview and Grokking the Object-Oriented Design Interview courses from Educative, and I must say they are excellent to prepare well.

These courses are designed by the hiring managers of Google, Facebook, Microsoft, and Amazon. They not only has a set of carefully handpicked case studies, which have been repeatedly asked at the top tech companies but also provide a thorough experience to handle different object-oriented design scenarios.






5 Object-Oriented and Software Design Interview Questions

Here is my list of frequently asked object-oriented and software design questions from programming job interviews. You will find such kinds of questions not only on biggies like Amazon, Google, Microsoft, and Facebook but also on small startups and service-based companies like Infosys, Wipro, TCS, and Cognizant.

Though for a comprehensive preparation, I also suggest you take a look at Java Programming Interview Exposed, which contains questions from all important Java topics, like Core Java, data structure and algorithms, multithreading, garbage collection, JVM internals, and frameworks like Spring and Hibernate.


Problem 1: Design a Vending Machine in Java (solution)

You need to design a Vending Machine which follows the following requirements
  • Accepts coins of 1,5,10,25, 50 Cents, i.e., penny, nickel, dime, and quarter as well as 1 and 2 dollar note
  • Allow user to select products e.g. CANDY(10), SNACK(50), NUTS(90), Coke(25), Pepsi(35), Soda(45)
  • Allow users to take a refund by canceling the request.
  • Return the selected product and remaining change if any
  • Allow reset operation for vending machine supplier
You need to use object oriented programming and design technique to solve this problem. You also need to create class diagram, sequence diagram and use case diagram to communicate your design to fellow developers. 


Problem 2: Design a URL shortener service like goo.gl (solution)

You need to design a URL shortener service like bit.ly or goo.gl. You can insert the full URL and get a short one. Your short URL should also record the stats about how many times it was accessed. Your system should also be able to handle concurrent users and millions of URL shortening per day. Think about auditing and bookkeeping, as well.

Btw, If you struggle to start with these questions, then you can also see the Grokking The System Design Interview, which contains a whole chapter on designing URL shortening services like TinyURL, Google URL, and Bitly.

Here is the system diagram from the same course, which explains the different components of a URL shortening service. I strongly suggest you check the course, this lesson is also available for a FREE preview.

Top 5 Object Oriented Design Interview Questions for Programmers, Software Engineers



Problem 3: Design a Lift system in your programming language. (solution)

An elevator is a combination of at least two elevators, one going up and another coming down. The goal is to minimize the waiting time of the user. Make sure you how your design will evolve if a lift is installed on high-rise buildings over 20 floors.

How many lifts do you need to serve 40 floors with a waiting time of no less than 30 seconds on average. Think about the parking strategy of your lift, i.e., which floor they should be resting on or should they keep going up or down, etc.



Problem 4: Design and implement LRU cache in Java or C++? (solution)

An LRU cache stands for Least Recently Used. It should remove the least recently used item from the cache to make space for a new item. Think about the persistence strategy of the cache. how do you build cache after crash etc? Let me give you a hint, you can use a LinkedHashMap to build an LRU cache in Java. 



Problem 5: Design a Traffic Controller System for a Junction?

You need to design software to control traffic lights at a junction where traffic is coming from four sides. It should follow basic traffic rules, allow a pedestrian to cross the road, and traffic to pass in a reasonable time. How do you optimize the waiting time with respect to high traffic from one direction, like during morning and evening rush hours?

If you need some help then a similar question about designing Airline Management System can be found on Grokking the Object-Oriented Design Interview course, you can go through that lesson to learn more about how to deal with such a question.

Top 5 Object Oriented Design Interview Questions for Programmers, Software Engineers


Problem 6: Design a Trade Position Aggregator or Portfolio Manager? 

You need to design a system where trades are fed at real time and you need to calculate live position by aggregating buy and sale trades for each symbol. You also need to allocate trades on accounts which is part of trade. 

Here are rules and constraints you need to follow while designing this system:
1. When Direction is Buy and operation is NEW or AMEND, you need to increase the position as your exposure increases. 
2.  When Direction is Sell and operation is CANCEL, you need to increase the position as your exposure is not reducing. 
3.  When Direction is Buy and operation is Cancel reduce position;
4. When Direction is Sell, and operation is NEW or AMEND, reduce positions.   

If you need a solution, you can see this tutorial where I have solved this question in Java, step by step.

Object Oriented Analysis and Design Interview Questions in Java

 


That's all in this list of frequently asked software design questions from programming job interviews. As I said, object-oriented analysis and design are some of the most sought-after skills in job interviews. If you can demonstrate excellent design and coding skills, along with writing a good JUnit test, it would create an excellent impression on the interviewer.

Everybody like good professional developers and unit testing is one of that thing which separate a professional to non-professional software engineers. If you have been asked any other object-oriented design question or anything related to software design, feel free to share it with us.

Other Programming Interview Questions for Java Programmers
  • 10 tricky Java Interview Questions for Experienced developers (list)
  • Top 5 Courses to learn System Design for Interviews (dev.to)
  • 21 frequently asked SQL Queries from Programming Interviews (list)
  • 18 Java design pattern interviews questions with answers (list)
  • My favorite courses to learn Software Architecture (medium)
  • 25 Software Design Interview Questions for Programmers (design questions)
  • 12 multi-threading and concurrency Interview Questions (list)
  • 7 Best Courses to learn Data Structure and Algorithms (best courses)
  • 40 Core Java Interview Questions from Phone Interviews  (list)
  • 7 Best Courses to learn OOP Design Pattern (best courses)
  • 21 Array Concept Interview Questions in Java? (list)
  • 10 Best SQL and Database Courses for Programmers (best courses)
  • 22 Java Inheritance Interview Questions with Answers (list)
  • 30 OOP Concept Interview Questions with Answers (list)
  • Top 20 System Design Interview Questions for Programmers (questions)
  • 10 tips and 101 Coding Problems to Crack Your Next Interview (article)
  • 50+ Data Structure and Algorithms Problems from Interviews (article)
  • 10 Courses to Crack your Programming Interviews (courses)

Thanks for reading this article so far. If you like these Object-Oriented Design Questions, then please share it with your friends and colleagues. If you have any questions or doubt then, please drop a note,

P. S. - If you need more questions, I suggest you check out the Grokking the Object-Oriented Design Interview course on Educative, an interactive learning platform. This course is a complete guide to master the OODI. It is designed by the hiring managers of Google, Facebook, Microsoft, and Amazon and contains solutions to some of the frequently asked object-oriented design questions from these tech giants.

5 comments:

  1. Great post.. can you post solutions as well ?

    ReplyDelete
  2. I am unable to understand problem 4, can you give a brief solution of it?
    Thanks in advance.
    Kemar J.

    ReplyDelete
  3. Replies
    1. Sorry, what do you mean? Are you not able to solve these problems or description not clear to you? The description has kept loose so that you don't have too many constraint to create solution.

      Delete

Feel free to comment, ask questions if you have any doubt.