OOD Design
Step 1:
Who is going to use it. How they are going to use it.
Or: Who, What, Where, When, how, Why
Step 2:
Define Core Objects.
Example:
- Resaturant:
Table, Guest, Party(Order), Order, WaitLine, Reservation, Meal, Employee, Server and Chef.
- Chess:
Table, Player, Piece
Step 3:
Analyze Relationship
- Many to Many
- One to Many
Talk to interviewer about how general purpose your design should be.
Example:
Resturant:
- One table has one Order, One order can have one or multi tables
- Server and Chef inherits from Employee.
- One table has one or multi Guest
- One wait line will keep the name of one order(party)
- The reserveation array will keep the name of reservation. Dictionary may be better
Step 4:
Inverstigate Actions
update your design
Example:
Resturant:
- Main Process
- Guests come
- Check Reservation
- Yes, Go to table
- No, Check Table empty
- empty, assign to the table.
- No empty, add it to the waiting line
- Guests sit down
- Assign a server to delivery the menu and beverages
- Get Order
- Send Order to chef(Then we need a queue for Order)
- Order was accept and cooked
- Delivery the dishes(Then we need dish class with price)
- Table checked out
- Server check the money and free the table
- Judge waiting line is empty or not
- Not, assign the table
- Empty, do nothing
- Reservation Process:
- Guest call and make a reserve
- Check table empty
- No, cannot reserve
- Yes, reserve and make the table reserved(so table can be empty, seated or reserved)
Design Pattern:
Singleton and Factory
Singleton:
Can only be instanced once, such as Chess table or restaurant's restaurant itself. So we may need static keyword.
Factory:
An interface for creating an instance of a class, such as create order.The factory method would take a parameter representing which class to instantiate.
===============================================================
Some samples:
Chat Server
Design Twitter
Design Hashtable
LRU Cache
Parking Lot
Tic-Tac-Toe
Call center
Some follow up questions:
what would be the hardest problems to solve?