使用面向对象的分析和设计为电梯建模[英] Modelling an elevator using Object-Oriented Analysis and Design

本文是小编为大家收集整理的关于使用面向对象的分析和设计为电梯建模的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

在面向对象的设计和分析方面,在访谈和课程中似乎通常存在一些问题.这是其中之一.不幸的是,我大学的OOP教授从未真正给出答案,所以我一直在想.

问题如下:设计一组基本的对象/方法,用于模拟电梯库.哪些对象及其属性/方法?

为了争论,让我们假设我们的建筑物有二十层;底层是大厅,二楼连接到停车场(因此,人们将进入/退出底楼或二楼的建筑物).有一家电梯银行为所有楼层提供服务.电梯库中有三个电梯轴,每轴有一个电梯.

在面向对象的模型中建模它的正确方法是什么?

推荐答案

首先有一个电梯类.它有一个方向(向上,向下,站立,维护),当前的地板和朝向方向排序的地板请求列表.它收到该电梯的请求.

然后有一家银行.它包含电梯并从地板上接收请求.这些安排到所有主动电梯(不在维护中).

调度将就像:

  • 如果可用
  • 其他选择搬到此楼层的电梯.
  • 其他地在另一层楼上选择站立电梯.
  • 否则选择最低负载的电梯.

每个电梯都有一组状态.

  • 维护:电梯对外部信号没有反应(仅对其自身信号).
  • 站:电梯固定在地板上.如果接到电话.电梯在那个地板上,门打开.如果它在另一个楼层,它将朝那个方向移动.
  • 向上:电梯向上移动.每次到达地板时,都会检查是否需要停止.如果是这样,它会停止并打开门.它等待一定的时间并关闭门(除非某个人通过它们移动.然后它从请求列表中删除地板并检查是否有另一个请求.如果是这样,电梯开始再次移动.如果没有,状态立场
  • down:就像向上一样,但在反向方向上.

还有其他信号:

  • 警报.电梯停止.如果它在地板上,门打开,请求列表已清除,请求转移回银行.
  • 门打开.如果电梯在地板上并且不移动,则打开门.
  • 门关闭.如果他们打开,关闭门.

编辑: 有些电梯不会从底部/first_floor ESP开始.如果摩天大楼.

min_floor&max_floor是电梯的两个附加属性.

其他推荐答案

唐纳德·诺斯(Donald Knuth)的《计算机编程艺术》 vol.1有电梯和数据结构的演示. Knuth提出了非常彻底的讨论和计划.

knuth(1997)"信息结构",计算机编程的艺术 vol. 1 pp.302-308

其他推荐答案

我已经看到了这个问题的许多变体.主要区别之一(决定了难度)之一是是否有一些集中式尝试具有"智能和高效的系统",该系统将具有负载平衡(例如,在早晨将更多的闲置电梯发送到大厅).如果是这样,设计将包括一个真正有趣的设计的整个子系统.

一个完整的设计显然太多了,在这里呈现,并且有许多Altenatives.宽度也不清楚.在一次采访中,他们将尝试弄清楚您的想法.但是,这些是您需要的东西:

  1. 中央控制器的表示(假设有一个).

  2. 电梯的表示

  3. 电梯接口单元的表示(这些可能不同于 电梯到电梯).显然也在每个楼层都调用按钮等.

  4. 每层箭头或指示器的表示形式(几乎是电梯模型的"视图").

  5. 人类和货物的表示(对于最大载荷中可能很重要)

  6. 建筑物的表示(在某些情况下,某些楼层有时会被阻止,等等)

本文地址:https://www.itbaoku.cn/post/627347.html

问题描述

There are a set of questions that seem to be commonly-used in interviews and classes when it comes to object-oriented design and analysis. This is one of them; unfortunately, my OOP professor in college never actually gave an answer to it, and so I've been wondering.

The problem is as follows: design a basic set of objects/methods to be used to simulate an elevator bank. What are the objects and their attributes/methods?

For the sake of argument, let us assume that our building has twenty floors; the bottom floor is the lobby, and the second floor connects to the parking garage (therefore, people will enter/exit the building on either the bottom floor or the second floor). There is one elevator bank that services all the floors; there are three elevator shafts in the elevator bank, and one elevator per shaft.

What would be the correct way to model this in an object-oriented model?

推荐答案

First there is an elevator class. It has a direction (up, down, stand, maintenance), a current floor and a list of floor requests sorted in the direction. It receives request from this elevator.

Then there is a bank. It contains the elevators and receives the requests from the floors. These are scheduled to all active elevators (not in maintenance).

The scheduling will be like:

  • if available pick a standing elevator for this floor.
  • else pick an elevator moving to this floor.
  • else pick a standing elevator on an other floor.
  • else pick the elevator with the lowest load.

Each elevator has a set of states.

  • Maintenance: the elevator does not react to external signals (only to its own signals).
  • Stand: the elevator is fixed on a floor. If it receives a call. And the elevator is on that floor, the doors open. If it is on another floor, it moves in that direction.
  • Up: the elevator moves up. Each time it reaches a floor, it checks if it needs to stop. If so it stops and opens the doors. It waits for a certain amount of time and closes the door (unless someting is moving through them. Then it removes the floor from the request list and checks if there is another request. If so the elevator starts moving again. If not it enters the state stand.
  • Down: like up but in reverse direction.

There are additional signals:

  • alarm. The elevator stops. And if it is on a floor, the doors open, the request list is cleared, the requests moved back to the bank.
  • door open. Opens the doors if an elevator is on a floor and not moving.
  • door closes. Closed the door if they are open.

EDIT: Some elevators don't start at bottom/first_floor esp. in case of skyscrapers.

min_floor & max_floor are two additional attributes for Elevator.

其他推荐答案

Donald Knuth's The Art of Computer Programming Vol.1 has a demonstration of elevator and the data-structures. Knuth presents a very thorough discussion and program.

Knuth(1997) "Information Structures", The Art of Computer Programming Vol. 1 pp.302-308

其他推荐答案

I've seen many variants of this problem. One of the main differences (that determines the difficulty) is whether there is some centralized attempt to have a "smart and efficient system" that would have load balancing (e.g., send more idle elevators to lobby in morning). If that is the case, the design will include a whole subsystem with really fun design.

A full design is obviously too much to present here and there are many altenatives. The breadth is also not clear. In an interview, they'll try to figure out how you would think. However, these are some of the things you would need:

  1. Representation of the central controller (assuming there is one).

  2. Representations of elevators

  3. Representations of the interface units of the elevator (these may be different from elevator to elevator). Obviously also call buttons on every floor, etc.

  4. Representations of the arrows or indicators on each floor (almost a "view" of the elevator model).

  5. Representation of a human and cargo (may be important for factoring in maximal loads)

  6. Representation of the building (in some cases, as certain floors may be blocked at times, etc.)

相关标签/搜索