一个包含单例模式、观察者模式和状态模式的、基于 JavaFX 图形界面的电梯模拟器。
This system is a kind of closed-loop control system. The data flow transit between different types of classes in this system is shown in Figure.1 below.
Observer pattern is applied on simulation of sensors and elevator controller, as the change of sensor should immediately be known by the elevator controller. Meanwhile, this pattern makes it easier to extend the type of sensors for the controller.
State pattern is applied on the Elevator Controller class to define the logic and transition rules of different states. This pattern improves the maintainability and extensibility of the states of elevator when add some functionality like elevator maintenance mode. The state diagram of Elevator Controller is shown in Figure 2.
To simulate the external environment, a class called Environment has been added to the design. This class defined a physical interface for the actuator classes (motors) to call, and it also perform a delay in the operation to simulate the real situation in the physical world. Singleton pattern is applied to this class, as there will be only one environment for an independent elevator controller. With singleton pattern, the actuator classes can directly access the environment class and environment won’t be referenced by the controller class.
The class diagram is shown in Figure 3.
This is a JavaFX application, and the main class is at cn/edu/neu/elevator/Main.java
Lingen Li, Chenming Chang, Jingqi Chen
This project license is MIT.