Object Oriented Design Problems

First we need to get familiar with the tool UML-diagram which would help us in the interviews to explain our thoughts clearly.
There are three basic relations, inheritance (arrow), association(line) and aggregation (diamond solid or shallow).

Here are some problem from the Crack the coding interview.
1. Design the data structures for a generic deck of cards. Explain how you would subclass it to implement particular card games.
First we decide what classes we will have. Say if we are implementing a blackjack game.
We need to have a card class, which will have the suit and the value. suit will come from a enum class and value is just an integer value (notice that the Ace and King Queen and Jack might need specific treatment). Then we will have a Deck class which will aggregate with the card class. Then we will need a hand class that will handle the distribution of cards and count the scores.

2. Imagine you have a call center with three levels of employees: fresher, technical lead (TL), product manager (PM). There can be multiple employees, but only one TL or PM. An incoming telephone call must be allocated to a fresher who is free. If a fresher can’t handle the call, he or she must escalate the call to technical lead. If the TL is not free or not able to handle it, then the call should be escalated to PM. Design the classes and data structures for this problem. Implement a method getCallHandler().
First the fresher, TL and PM have common entries such as name, salary, address, that can be put into a common subclass, each of them will also have a rank which differ them from each other. The callHandler will take the call and put all the call in a queue, and distribute the call according to the rank to different employee.

3.Design a musical juke box (MP3 player like ipod) using object oriented principles
First lets break down the components:
Player itself.
Flash that stores songs.
Display that display the info about the song
Then we further break down the components to functions
PlayList that queue up the song will be played

4. Design a chess game using object oriented principles
We need a chess board to record the name, and a handler to handle the input of the users, Then each chess piece will have some common attributes so they can be put into a basic class while each of them can inherit the base class and add their own attributes.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s