Connectors
Interfaces alone are not enough. Interconnections are needed to specify the flow of information. Connectors between ports can only be used in decomposed components. A port can be connected to multiple other ports of compatible direction, type, and timing.
Since the elevator and the system as a whole are the only decomposed components, we only need to add connectors in these.
First, we forward the openDoor
information from the elevator to the door.
package elevator;
component Elevator {
port in boolean openDoor;
Door door;
openDoor -> door.shouldOpen;
}
A connector has its source on the left and target on the right. If we want to connect a subcomponent's port, we use a format of subcomponentName.portName
.
Our overall system contains more than one connection. We connect all subcomponents using the corresponding ports.
package elevator;
component ElevatorSystem {
port in int pressedOnFloor;
Elevator elevator;
ControlStation control;
Motor motor;
pressedOnFloor -> control.requestOnFloor;
control.openDoor -> elevator.openDoor;
motor.position -> control.motorPosition;
control.motorCommand -> motor.command;
}
With the connectors present, we can clearly see why the controller has to have a delayed port. The connectors build a circle, also called a feedback loop, where the inputs depend on the outputs.
In the last step, we will add behavior to the remaining components, giving us a system that we can simulate and interact with.
A detailed decomposition reference can be found here