From: https://discuss.leetcode.com/topic/89/write-elevator-program-using-event-driven-programming/9

We can divide into three main components:

  1. User

    • User presses the floor button (can be up or down direction) to summon the elevator.
    • User presses the elevator button to go to the destination floor.
  2. Button

    • An elevator has buttons (ElevatorButton) inside allowing user to choose the destination floor.
    • Each floor has two buttons (FloorButton) to summon the elevator to go up or down from that floor.
    • When the user presses the button, it illuminates.
    • When the elevator reaches the desired floor, the button stops illuminating.
    • Calls placeRequest() to insert into the ElevatorRequest queue when button is pressed.
  3. Elevator

    • Open or close door.
    • Moves up/down.
    • Stores states such as direction (up/down), speed, currentFloor.

We need a queue to store all request, this can all be encapsulated in an ElevatorRequests class. When a user presses a button, this request has to be served and is added to the processing queue. Elevator requests can be scheduled using different scheduling algorithms. ElevatorController controls the elevator by giving it instructions such as move up/down, or start/shutdown. The elevator controller reads the next elevator request and serves it.

分析:

这个设计还可以,但是里面有些问题:

1. Controller 里还缺少process() 这样的方法,这个方法的实现应该是一个while loop, 每次执行玩一个request, 就从ElevatorRequest取下一个requet. 只要从ElevatorRequest返回的request不为空,就应该按照request的楼层前进。而且,Controller里不但有Elevator的reference, 也需要有ElevatorRequest对象的reference. 这两个reference 在Controller constructor里得到初始化。

2. Button 里需要有ElevatorRequest对象的索引。

3. Button里不需要有direction. CurrentFloor 和 destinFloor 就决定了direction. 在现实生活中也是只要的。

Design Elevator的更多相关文章

  1. Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]

    作业提交时间:10月9日上课前. Design and implement an Elevator Scheduler to aim for both correctness and performa ...

  2. 软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]

    软件工程  ---   Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] 说明结对编程的优点和缺点. 结对编程的优点如下: 在独立设计.实现代码的过程中不 ...

  3. cf472B Design Tutorial: Learn from Life

    B. Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes ...

  4. Codeforces Round #270--B. Design Tutorial: Learn from Life

    Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes in ...

  5. Elevator poj3539

    Elevator Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 1072   Accepted: 287 Case Time ...

  6. BUAAOO P5-P7 Elevator Simulation

    目录 Abstract Introduction Topic Request Elevator Analysis Reading Requests Coordinating Scheduling an ...

  7. SAP Process Integration - High Level ERP/Integration Process --- Cargill Process Concept Design

    Customer Industry: Commercial off-the-shelf (COTS) application ,, Food Ingredients or Agricultural S ...

  8. UVALive 2949 Elevator Stopping Plan(二分 + 贪心)

    ZSoft Corp. is a software company in GaoKe Hall. And the workers in the hall are very hard-working. ...

  9. POJ3539 Elevator

    Time Limit: 4000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu Description Edward wor ...

随机推荐

  1. C#指定日期为一年中的第几周

    /// <summary> /// 获取指定时间在为一年中为第几周 /// </summary> /// <param name="dt">指定 ...

  2. Mono资源

    摘要 最近看了一部分mono方面的资料,这里整理一下,在这里列一个目录,方便以后用到的时候查找. Mono Mono 是一个由 Xamarin 公司(先前是 Novell,最早为 Ximian)所主持 ...

  3. [Asp.Net]获取客户端ip和mac地址

    摘要 有时候,我们需要获取客户端的一些信息,以便进行统计.比如:客户端的唯一标识,ip等信息 IP 通过获取HTTP_X_FORWARDED_FOR,或者REMOTE_ADDR可以获取客户端的ip. ...

  4. jquery mobile常用的data-role类型 data-icon data-iconpos

    文章链接: http://blog.csdn.net/cainiaoxiaozhou/article/details/48521241

  5. TeX — Beauty and Fun

    我是初学者,你推荐使用什么发行的 TeX? 我应该用 LaTeX 吗? 我认为最好的发行是 TeXLive CD,它不但包含了所有操作系统需要的程序,而且有许许多多宏包,如果你不是特别特殊的用户,有了 ...

  6. oracle中的连接查询与合并查询总结

    连接查询: 连接查询是指基于多张表或视图的查询.使用连接查询时,应指定有效的查询条件,不然可能会导致生成笛卡尔积.如现有部门表dept,员工表emp,以下查询因查询条件无效,而产生笛卡尔积:   (各 ...

  7. Git工作流总结

    引用自:https://github.com/xirong/my-git/blob/master/git-workflow-tutorial.md 说明: 个人在学习Git工作流的过程中,从原有的 S ...

  8. oracle 使用ID关键字作列名导致索引失效

    oracle表空间变更导致主键索引失效,重建索引即可

  9. Apache常用2种工作模式prefork和worker比较

    Apache两种常用工作模式:prefork和worker. prefork MPM prefork是一个非线程型的.预派生的MPM,使用多个进程,每个进程在某个确定的时间只单独处理一个连接,效率高, ...

  10. 一次失败的动态转换bean的尝试与思考

    前因 公司规范确定不允许使用反射类的进行属性bean的拷贝了,只允许手动的get/set,可以猜到这样定义的原因是制定规范的同事认为反射性能低,虽然写get/set慢点好在性能高.平时开发的时候也是迫 ...