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?

  • 相关阅读:
    你不知道JavaScript--作用域、LHS查询和RHS查询
    学习koa开发API(六)--- 页面开发和准备需要的接口文档
    学习koa开发API(五)--- 对异常和参数的处理
    学习koa开发API(四)--- 文件目录设置
    学习koa开发API(三)--- OPTIONS请求的理解和处理
    学习koa开发API(二)--- 认识Koa-Router和获取参数
    学习koa开发API(一)--- 认识RESETful API和KOA
    No.4
    盒子模型
    CSS布局总结(三)
  • 原文地址:https://www.cnblogs.com/renyualbert/p/6007409.html
Copyright © 2011-2022 走看看