You are on page 1of 25

Structural models

COMP3297 by Leo Yeung L5 - System Modeling 23


Structural models and Class diagrams

² Structural models
§ display the organization of a system in terms of the
components that make up that system and their relationships.
§ may be static models, which show the structure of the system
design, or
§ dynamic models, which show the organization of the system
when it is executing.
² Class diagrams
§ are used when developing an object-oriented system model to
show the classes in a system and the associations between
these classes.
1 1 Patient
Patient record

COMP3297 by Leo Yeung L5 - System Modeling 24


What is a Class?

Each Object was built from the same set of


A Class is a blueprints and therefore contains the same
blueprint for properties and methods.
an object.

Object is an
instance of
a class.

(Ref: Link)
COMP3297 by Leo Yeung L5 - System Modeling 25
What do the UML notations mean?

1) Class – A class can be thought 2) Association - a link between


of as a general definition of one classes indicates there is some
kind of system object. relationship between these classes.

1 1 Patient
Patient record

Each patient record 3) The association Each patient has exactly


maintains information is annotated with one record
about exactly one patient. “1”s in both sides:
It means a 1:1
relationship
between objects
of these classes.

COMP3297 by Leo Yeung L5 - System Modeling 26


What do the UML notations mean?
2) (1 .. *) Multiplicity: Represents
indefinite number if objects are involved. 3) Name of the Association may be
• (Number at LHS) A Patient may placed near in the middle of the line.
suffer from several conditions. Consultant
• (Number at RHS) The same
condition may be associated with 1
several patients. referred-to
1..*
1..* 1..* 1..* 1 (Ref: Link)
Condition Patient General
referred-by practitioner
diagnosed-
with 1..*
attends
1..*
prescribes
1) (Number .. Number): Consultation Medication
Represent Multiplicity – It 1..* 1..*
shows the exact number of 1..*
objects, e.g. (0..1), (1..4). runs
Involves prescribes
1..4 Treatment
In this example, each 1..*
consultation involves 1-4 Hospital
hospital doctor(s) Doctor
Example: Classes and associations in the MHC-PMS
COMP3297 by Leo Yeung L5 - System Modeling 27
What do the UML notations mean?

1) the 1st partition:


Represent Class name Consultation
(mandatory info)
Doctors
Date
Time
2) the 2nd partition: Clinic
Represent Class Reason
Attributes
Medication prescribed
Treatment prescribed
Voice notes
Transcript
...

3) the 3rd partition: New ( )


Represent Class Prescribe ( )
Operations (Methods) RecordNotes ( )
Transcribe ( )
...

Example: The Consultation class


COMP3297 by Leo Yeung L5 - System Modeling 29
UML Class Notation and Visibility

1) Each attribute has a type

2) Each operation has a signature

3) Return int

4) Parameter n is of
type int

5) Visibility
+ denotes public attributes or operations
- denotes private attributes or operations
COMP3297 by Leo Yeung L5 - System Modeling 30
Perspectives of Class Diagram

² Class diagram can be interpreted from various perspectives:

represents the focus is on the describes how


concepts in the interfaces of Abstract classes will
domain Data Type (ADTs) in implement their
the software interfaces

COMP3297 by Leo Yeung L5 - System Modeling 31


Generalization

• Generalization manages complexity Doctor


Generalization
• Infers that different members of these
classes (e.g. Hospital doctor, General Hospital
doctor
General
practitioner

practitioner) have some common


characteristics (e.g. Doctor) Consultant Team doctor

• Advantage: If changes are proposed, then


you do not have to look at all classes in the Trainee Qualified
doctor doctor
system to see if they are affected by the
change. Doctor

• In object-oriented languages, such as Java,


Name
Phone #
Email

generalization is implemented using the register ( )


de-register ( )

class inheritance mechanisms built into the


language. Hospital doctor General practitioner

Staff # Practice
Pager # Address

COMP3297 by Leo Yeung L5 - System Modeling 32


What do the UML notations mean?

Arrowhead pointing up: Represent


Generalization – pointing up to a more
Doctor
general class. It forms an "is-a"
relationship.

Hospital General
doctor practitioner In this example,
a) General practitioners and hospital
doctors can be generalized as
doctors
Consultant Team doctor
b) There are three types of Hospital
Doctor:
I. Trainee Doctor
Trainee Qualified II. Qualified doctor
doctor doctor III. Consultant

COMP3297 by Leo Yeung L5 - System Modeling 33


What do the UML notations mean?

Doctor The lower-level classes are subclasses


Name that inherit the attributes and
Phone # operations from their superclasses.
Email

register ( ) In this example,


de-register ( ) • All doctors, including hospital
doctor and general practitioner,
have a name, phone number and
email.
Hospital doctor General practitioner

Staff # Practice
Pager # Address
These lower-level classes then add more
specific attributes and operations.
In this example,
• All hospital doctors have a staff number and carry a pager.
• General practitioners do not have these attributes, as they
work independently, but they have an individual practice
name and address.
COMP3297 by Leo Yeung L5 - System Modeling 34
Object class aggregation models

² An aggregation model shows how classes that are


collections are composed of other classes.

A diamond shape added to the link next


to the class that represents the whole:
Patient record Define aggregation - one object (the
whole) is composed of other objects
1 1 (the parts). It forms a “part of”/ “has a”
relationship.
1 1..*
In this example,
Patient Consultation
• A patient record is composed of a
Patient and an indefinite number
of Consultations.

COMP3297 by Leo Yeung L5 - System Modeling 35


Generalization vs Aggregation

Generalization Aggregation
“is a” relationship “has a” relationship

Question
What is the difference
considering implementation?

(Ref: Link)
COMP3297 by Leo Yeung L5 - System Modeling 36
All notations in a Class Diagram: Order System

COMP3297 by Leo Yeung L5 - System Modeling 37


Behavioral models

COMP3297 by Leo Yeung L5 - System Modeling 38


Behavioral models

² Behavioral models are models of the dynamic behavior of a


system as it is executing. They show what happens or what is
supposed to happen when a system responds to a stimulus from
its environment. There are two types of stimuli:
§ Data - Some data arrives that has to be processed by the system.
§ Events - Some event happens that triggers system processing. Events
may have associated data, although this is not always the case.
² Event-driven modeling
§ Real-time systems are often event-driven, with minimal data
processing. For example, a landline phone switching system
responds to events such as ‘handset activated’ by generating a
dial tone.
§ Event-driven modeling shows how a system responds to
external and internal events.
COMP3297 by Leo Yeung L5 - System Modeling 39
State machine models

² These model the behaviour of the system in response to


external and internal events.
² They show the system’s responses to stimuli so are
often used for modelling real-time systems.
² State machine models show system
states as nodes and events (or
transition/trigger) as arcs between
these nodes. When an event occurs, the
system moves from one state to another.

COMP3297 by Leo Yeung L5 - System Modeling 40


Assumptions of a simple microwave oven

an alphanumeric display to display various


alerts and warning messages
a numeric keypad to input the cooking time
a start button and a cancel button
a switch to select full or half power

² Sequence of actions in using the microwave oven


1. Select the power level (either half power or full power).
2. Input the cooking time using a numeric keypad.
3. Press Start and the food is cooked for the given time.
² For safety reasons, the oven should not operate when the door is
open. On completion of cooking, a buzzer is sounded.

COMP3297 by Leo Yeung L5 - System Modeling 41


What do the UML notations mean?
3) Rounded rectangle: Represent system states,
4) Labeled arrow: including brief description, following “do” of the
Represent stimuli Full actions taken in that state. May add “entry” and
that force a power Full power
“exit” for actions performed on entry to state and
do: set power
transition from one = 600 on leaving state respectively.
state to another
Timer
Waiting
Number
do: display Operation
Full Set time
time
power do: operate
1) Solid circle: do: get number
exit: set time oven
Represent Half
power
Half
initial state. power
Door
Cancel
Timer closed
Start
Door
open Door
Half power Enabled Waiting
open
do: set power Door do: display do: display
= 300 closed 'Ready' time

Disabled
do: display
'Waiting'
2) Concentric circle:
Example: State diagram of a microwave oven Represent final state.
COMP3297 by Leo Yeung L5 - System Modeling 42
Microwave oven operation

1) Rounded Operation
Time
square: Represent Checking
Superstate (e.g. OK Cook
do: check do: run
Operation)
status generator
containing a set of
substates (e.g. Turntable Emitter Timeout
Checking, Cook, fault fault
Alarm, Done)
Done
Alarm
do: buzzer on
do: display
for 5 secs.
event

Door open Cancel

Disabled Waiting

COMP3297 by Leo Yeung L5 - System Modeling 43


States and stimuli for the microwave oven

State Description Stimulus Description


Waiting The oven is waiting for input. The display Half power The user has pressed the half-power
shows the current time. button.
Half power The oven power is set to 300 watts. The Full power The user has pressed the full-power
display shows ‘Half power’. button.
Full power The oven power is set to 600 watts. The Timer The user has pressed one of the timer
display shows ‘Full power’. buttons.
Set time The cooking time is set to the user’s input Number The user has pressed a numeric key.
value. The display shows the cooking time
Door open The oven door switch is not closed.
selected and is updated as the time is set.
Door closed The oven door switch is closed.
Disabled Oven operation is disabled for safety. Interior
oven light is on. Display shows ‘Not ready’. Start The user has pressed the Start button.
Enabled Oven operation is enabled. Interior oven light Cancel The user has pressed the Cancel button.
is off. Display shows ‘Ready to cook’.
Operation Oven in operation. Interior oven light is on.
Display shows the timer countdown. On
completion of cooking, the buzzer is sounded
for five seconds. Oven light is on. Display
shows ‘Cooking complete’ while buzzer is
sounding.

COMP3297 by Leo Yeung L5 - System Modeling 44


Example of a state machine diagram derived from a
Class - "BookCopy"

Option 1:

Option 2:

(Ref: Link)
COMP3297 by Leo Yeung L5 - System Modeling 46
Real Example – Vendor Presentation

² Are you ready to present your idea and solution?

COMP3297 by Leo Yeung L5 - System Modeling 47


Key points

² A model is an abstract view of a system that ignores system


details. Complementary system models can be developed to
show the system’s context, interactions, structure and
behavior.
² Context models show how a system that is being modeled is
positioned in an environment with other systems and
processes.
² Use case diagrams and sequence diagrams are used to
describe the interactions between users and systems in the
system being designed. Use cases describe interactions
between a system and external actors; sequence diagrams
add more information to these by showing interactions
between system objects.
COMP3297 by Leo Yeung L5 - System Modeling 48
Key points

² Structural models show the organization and architecture of a


system. Class diagrams are used to define the static structure
of classes in a system and their associations.
² Behavioral models are used to describe the dynamic behavior
of an executing system. This behavior can be modeled from
the perspective of the data processed by the system, or by
the events that stimulate responses from a system.
² State diagrams are used to model a system’s behavior in
response to internal or external events.

COMP3297 by Leo Yeung L5 - System Modeling 49

You might also like