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

查看:353
本文介绍了使用面向对象分析和设计建模电梯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在面向对象的设计和分析方面,有一些问题似乎在面试和课堂中常用。这是其中之一;不幸的是,我的OOP大学教授从来没有给出答案,所以我一直在想。

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).

计划将如下所示:


  • 如果可用,请选择这个楼层的电梯。

  • 否则选择一个移动到这个楼层的电梯。

  • 否则选择一个

  • 否则请选择最低负载的电梯。

  • 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.

还有其他信号:


  • 闹钟电梯停止,如果是在地板上,门打开,请求清单被清除,请求移动返回银行。

  • 门打开。如果电梯在地板上,不能移动,打开门。

  • 门关闭。关闭门如果他们是开放的。

编辑:
有些电梯没有从底部开始/ first_floor esp摩天大楼的情况。

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

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

min_floor & max_floor are two additional attributes for Elevator.

这篇关于使用面向对象分析和设计建模电梯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆