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?

  • 相关阅读:
    Springboot操作域对象
    Thymeleaf的条件判断和迭代遍历
    Thymeleaf的字符串与变量输出的操作
    window 2003 实现多用户远程登录
    非常漂亮js动态球型云标签特效代码
    Echarts运用
    sass、less和stylus的安装使用和入门实践
    java,js 解unicode
    Java上传下载excel、解析Excel、生成Excel
    小知识点应用
  • 原文地址:https://www.cnblogs.com/renyualbert/p/6007409.html
Copyright © 2011-2022 走看看