zoukankan      html  css  js  c++  java
  • 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
    1. Guests come
    2. Check Reservation
    3. Yes, Go to table
    4. No, Check Table empty
    5. empty, assign to the table.
    6. No empty, add it to the waiting line
    7. Guests sit down
    8. Assign a server to delivery the menu and beverages
    9. Get Order
    10. Send Order to chef(Then we need a queue for Order)
    11. Order was accept and cooked
    12. Delivery the dishes(Then we need dish class with price)
    13. Table checked out
    14. Server check the money and free the table
    15. Judge waiting line is empty or not
    16. Not, assign the table
    17. Empty, do nothing
    • Reservation Process:
    1. Guest call and make a reserve
    2. Check table empty
    3. No, cannot reserve
    4. 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?

  • 相关阅读:
    转载--Linux命令top动态观察程序的变化
    转载--C语言运算符优先级和口诀
    区别typedef和#define
    spring+springmvc+mybatis xml配置文件
    解决SmartGit序列号问题
    通过SmartGit把java maven项目传到码云
    301跳转
    mybatis之联表查询
    MySQL不常用、易忽略的小知识
    JavaScript精进篇
  • 原文地址:https://www.cnblogs.com/renyualbert/p/6007409.html
Copyright © 2011-2022 走看看