Chapter1 Train UML Example
Chapter1 Train UML Example
Chapter1 Train UML Example
Purposes of example: Follow a design through several levels of abstraction. Gain experience with UML.
header
address
command
ECC
Requirements
Console can control 8 trains on 1 track. Throttle has at least 63 levels. Inertia control adjusts responsiveness with at least 8 levels. Emergency stop button. Error detection scheme on messages.
Requirements form
name purpose inputs model train controller control speed of <= 8 model trains throttle, inertia, emergency stop, train # outputs train control signals functions set engine speed w. inertia; emergency stop performance can update train speed at least 10 times/sec manufacturing cost $50 power wall powered physical console comfortable for 2 hands; < 2 size/weight lbs.
Conceptual specification
Before we create a detailed specification, we will make an
Gives us practice in specification and UML. Good idea in general to identify potential problems before
Time
Message classes
command
estop
class. Attributes and operations will be filled in for detailed specification. Implemented message classes specify message type by their class. May have to add type as parameter to data structure in implementation.
relationships.
1 receiver 1 detector* 1 1
Detailed specification
We can now fill in the details of the conceptual
specification: more classes; behaviors. Sketching out the spec first helps us understand the basic relationships in the system.
duty cycle
+ V -
Class descriptions
panel class defines the controls. new-settings() behavior reads the controls. motor-interface class defines the motor speed held as
state.
Class descriptions
transmitter class has one behavior for each type of
message sent. receiver function provides methods to: detect a new message; determine its type; read its parameters (estop has no parameters).
current train. The operate() operation performs the basic formatting task.
train. Changing train number: must change soft panel settings to reflect current trains speed, etc. Controlling throttle/inertia/estop: read panel, check for changes, perform command.
Formatter class
formatter current-train: integer current-speed[ntrains]: integer current-inertia[ntrains]: unsigned-integer current-estop[ntrains]: boolean send-command() panel-active() : boolean operate()
Panel-active behavior
(in the formatter class)
T panel*:read-train()
current-train != train-knob
F T
panel*:read-speed()
current-speed != throttle
...
several commands.
receive-command() issue-command()
set-speed
estop type=000
Summary
Separate specification and programming. Small mistakes are easier to fix in the spec. Big mistakes in programming cost a lot of time. You cant completely separate specification and