4. UNIT â 2: ADVANCED CLASS MODELING, STATE
MODELING:
Advanced object and class concepts; Association ends; N-ary
associations; Aggregation; Abstract classes; Multiple inheritance;
Metadata; Reification; Constraints; Derived data; Packages;
Practical tips.
State Modeling: Events, States, Transitions and Conditions; State
diagrams; State diagram behaviour; Practical tips.
5. Advanced object and class concepts
Enumerations
Multiplicity
Scope
Visibility
6. Enumeration
Data type - a set of values together with a set of operations on those
values
īTo define a new simple data type, called enumeration type, we need
2 things:
īA name for the data type
īA set of values for the data type
īenum {FALSE, TRUE};
īenum rank {TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT,
NINE, TEN, JACK, QUEEN, KING, ACE};
īenum colors {BLACK, BLUE, GREEN, CYAN, RED};
īThe values are written in all caps because they are constants
7. Enumerations
īWhen constructing a model, we should carefully note enumerations,
because they often occur and are important to users.
īEnumerations are also significant for an implementation; we may
display the possible values with a pick list.
īDo not use a generalization to capture the values of an Enumerated
attribute.
īAn Enumeration is merely a list of values; generalization is a means
for structuring the description of objects.
8. Enumerations
īIn the UML an enumeration is a data type.
ī The second section lists the enumeration values.
īEg: Boolean type= { TRUE, FALSE}
9.
10. SSccooppee
UML specifies two types of scope for members: instance and classifier.
īClassifier members are commonly recognized as âstaticâ in many
programming languages. The scope is the class itself.
īAttribute values are equal for all instances
īMethod invocation does not affect the instanceâs state
īInstance members are scoped to a specific instance.
īAttribute values may vary between instances
īMethod invocation may affect the instanceâs state (i.e., change
instanceâs attributes)
īTo indicate a classifier scope for a member, its name must be underlined.
Otherwise, instance scope is assumed by default.
11. 11
Scope
īIndividual member data (attributes) may have either class
scope or instance scope.
īClass scope - A single copy of an attribute is shared by all
instances of a class.
ī In UML you underline the attribute to indicate class scope:
productCount : int
īInstance scope - Each instance of a class would have its own
copy of the attribute. All attributes have instance scope by
default.
13. Visibility
īVisibility refers to the ability of a method to reference a feature from another
class and has the possible values of public, protected & private.
īPublicâVisible anywhere that the class in which it appears is visible;
denoted by +.
īPackageâVisible anywhere in the package containing the class in which it
appears; denoted by ~.
īProtectedâVisible in the class in which it appears and all its sub-classes;
denoted by #.
īPrivateâVisible only in the class in which it appears; denoted by -
īRestricting visibility is the same as restricting accessibility.
14. Visibility
īThe UML denotes visibility with a prefix
īâ+â public
īâ-â private
īâ#â protected
ī â~â package
16. N-ary Association
īAn n-ary association is like a common (binary) association, except
that more than two association roles involved in it.
īThe UML symbol for n-ary associations is a diamond with lines
connecting to related classes. If the association has a name, it is written in
italics next to the diamond.
N-ary
association
Class1 Class2
Class3
Ternary
association
18. N-ary Associations
Train
date
trainNo
Seat
carriageNo
seatNo
Reservation
1 1..*
1..*
Passenger
name
title
19. N-ary Associations
īWe may occasionally encounter n-ary associations (association
among 3 or more classes).
īBut we should try to avoid n-ary associations- most of them
can be decomposed into binary associations, with possible
qualifiers and attributes.
22. 22
Aggregation
īA special form of association that models a whole-part relationship between
an aggregate (the whole) and its parts.
īModels a âis a part-part ofâ relationship.
īThe aggregation association represents the part-whole relation between
classes.
īDenoted by a solid diamond and lines
īDiamond attaches to the aggregate (whole) while lines attach to the parts
īMay have all association adornments
Car Door House
Whole Part
23. 23
Aggregation (cont.)
Car Door House
Whole Part
īAggregation tests:
īIs the phrase âpart ofâ used to describe the relationship?
ī A door is âpart ofâ a car
īAre some operations on the whole automatically applied to its
parts?
ī Move the car, move the door.
īAre some attribute values propagated from the whole to all or some
of its parts?
ī The car is blue, therefore the door is blue.
ī A door is part of a car. A car is not part of a door.
25. Composition
īComposition is a form of aggregation with strong
ownership and coincident lifetime of the parts by the
whole; the part object may belong to only one whole â
the parts are usually expected to live and die with the
whole.
(usually, any deletion of the whole is considered to
cascade to the parts}{filled diamond}
25
26. Aggregation and Composition
īAggregation is a special form of association that specifies a whole-part
relationship between the aggregate (the whole) and a component (the part);
aggregation is the part-of relationship. { it is a special form of association
in which a collection of objects, each having an independent existence, is
associated with an single object} {unfilled diamond}
īComposition is a form of aggregation with strong ownership and
coincident lifetime of the parts by the whole; the part object may belong to
only one whole â the parts are usually expected to live and die with the
whole.
(usually, any deletion of the whole is considered to cascade to the parts}
{filled diamond}
27.
28.
29. Metadata
īThe term "meta" comes from a Greek word that denotes
something of a higher or more fundamental nature.
Metadata, then, is data about other data.
īThe term refers to any data used to aid the identification,
description and location of networked electronic resources
30. Defining Metadata
īLibrarians equate it with a complete bibliographic record
īInformation technologists equate it to database schema or
definitions of the data elements
īArchivists include context information, restrictions and
access terms, index terms, etc.
31. Metadata
īMetadata is data that describes other data. For example, a class
definition is a metadata.
īModels are inherently metadata, since they describe the things
being modeled (rather than being the things).
īMany real-world applications have metadata, such as parts
catalogs, blueprints, and dictionaries. Computer-languages
implementations also use metadata heavily.
32. Derived Data
īA derived element is a function of one or more elements, which in
turn may be derived.
ī A derived element is redundant, because the other elements
completely determine it.
īUltimately, the derivation tree terminates with base elements.
īClasses, associations, and attributes may be derived.
īThe notation for a derived element is a slash in front of the element
name along with constraint that determines the derivation.
34. Packages
īA package is a group of elements (classes, association,
generalization, and lesser packages) with a common theme.
īA package partitions a model making it easier to understand and
manage. Large applications my require several tiers of packages.
īPackages form a tree with increasing abstraction toward the root,
which is the application, the top-level package.
īNotation for package is a box with a tab.
36. When to use Package
īTo create a overview of a large set of model elements
īTo organize a large model
īTo group related elements
37.
38. State Modeling
īState model describes the sequences of operations that occur in
response to external stimuli.
īThe state model consists of multiple state diagrams, one for each
class with temporal behavior that is important to an application.
īThe state diagram is a standard computer science concept that relates
events and states.
īEvents represent external stimuli and states represent values objects.
39. Elements of State Diagrams
īThe basic elements of state diagrams are
īEvents â An event is an occurrence at a point in time
īstates â the state in which the object finds itself at any moment
ītransitions â take the object from one state to another
īactions â take place as a result of a transition
40. Events
īAn event is an occurrence at a point in time such as â
User presses left button
Indigo flight departs from Mumbai
īAn event happens instantaneously with regard to time scale of
an application.
īOne event may logically precede or follow another, or the two
events may be unrelated (concurrent; they have no effect on
each other).
41. Types of Events
An event may be one of 3 types
īSignal event
īTime event
īChange event
42. Signal Event īA signal is an explicit one-way transmission of information from one
object to another.
īAn object sending a signal to another object may expect a reply, but
the reply is a separate signal under the control of the second object,
which may or may not choose to send it.
ī A signal event is the event of sending or receiving a signal (concern
about receipt of a signal).
īThe difference between signal and signal event
īa signal is a message between objects
īa signal event is an occurrence in time.
43. Time Event
īTime event is an event caused by the occurrence of an absolute
time or the elapse of a time interval.
īUML notation for an absolute time is the keyword when
followed by a parenthesized expression involving time.
īThe notation for a time interval is the keyword after followed
by a parenthesized expression that evaluates to a time
duration.
when (date = jan 1, 2000 )
44. Change Event
A change event occurs whenever a specified condition is met
īEvent name is specified as keyword when
īParameter list is a Boolean expression
īThe event occurs when both of the following conditions are met,
irrespective of the order when they happen
ī The expression evaluates to true
ī The object is in the required state
when (battery power < lower limit )
when (tire pressure < minimum pressure )
45. States
īState is a condition or situation during the life of an object within
which it performs some activity, or waits for some events
īThe objects in a class have a finite number of possible states.
īEach object can be in one state at a time.
īA state specifies the response of an object to input events.
ī At any given point in time, the system is in one state.
īIt will remain in this state until an event occurs that causes it to
change state.
īEvent vs. States
īEvent represents points in time.
īState represents intervals of time.
46. States
īA state is when a system is:
Doing something â e.g., heating oven, mixing
ingredients, accelerating engine,
Waiting for something to happen â Waiting for user to
enter password, waiting for sensor reading.
47. Eg:
power turned on power turned off power turned on
Time
Powered
Not powered
A state corresponds to the interval between two events received by an
object.
The state of an object depends on past events.
48. Basic UML Syntax
īA state is drawn with a
round box, with three
compartments for
īname
īstate variables (if any)
īactions to be performed
Name
state variables
actions
sometimes
left out when
empty
49.
50. Transitions
īA transition is a relationship between two states indicating that an
object in the first state will enter the second state.
īA transition is an instantaneous change from one state to another.
īThe transition is said to fire upon the change from the source state to
target state.
īA guard condition must be true in order for a transition to occur.
īA guard condition is checked only once, at the time the event occurs,
and the transition fires if the condition is true.
51. 51
Transition
A directed relationship between two states.
Contains five parts
ī Source state - current state before transition fires.
ī Event trigger - external stimulus that has the potential to
cause a transition to fire.
ī Guard condition - a condition that must be satisfied before
a transition can fire.
ī Target state - new state after transition fires.
52. Basic UML Syntax
īA transition is drawn with
an arrow, possibly labeled
with
īevent causing the
transaction
īguard condition
īAction to perform
AnEvent [guard] / SomeAction
54. Billing Example
State Diagrams show the sequences of states an object goes through
during its life cycle in response to stimuli, together with its responses
and actions; an abstraction of all possible behaviors.
Start End
Unpaid
Paid
Invoice created paying Invoice destroying
55. event action, taken during
AddParticipant / Set count = 0
cancel seminar
transition
Setup
do/initialize seminar
Available
do/initialize seminar
[ count = 20 ]
Full
do/finalize seminar
guard
Canceled
do/refund payments
cancel seminar
multiple
exits
cancel
seminar
aktivity, carried out
while in that state
56. Actions
īAction
īis an executable atomic computation
īincludes operation calls, the creation or destruction of
another object, or the sending of a signal to an object
īassociated with transitions and during which an action is not
interruptible -- e.g., entry, exit
57. Predefined Action Labels
âentry/â
īidentifies an action, specified by the corresponding action expression,
which is performed upon entry to the state (entry action)
âexit/â
īidentifies an action, specified by the corresponding action expression,
that is performed upon exit from the state (exit action)
âdo/â
īidentifies an ongoing activity (âdo activityâ) that is performed as long as
the modeled element is in the state or until the computation specified by
the action expression is completed (the latter may result in a completion
event being generated).
âinclude/â
īis used to identify a submachine invocation. The action expression
contains the name of the submachine that is to be invoked.
58. State Diagrams notation
Initial state final state
paying
Unpaid Paid
Invoice
created
Invoice
destroyed
name
state
transition
event
59. Hereâs a simple example SD for a
washing machine.
State
Transition
Condition
Action
60. 60
A condition is typically some kind of event,
e.g.:
âĸSignal
âĸArrival of an object (data/material),
âĸEtcâĻ
An action is the appropriate output or response
to the event, e.g.:
âĸSignal or message
âĸTransfer of an object,
âĸCalculation,
âĸEtcâĻ
Condition
Action
61. State Diagrams (Traffic light example)
Traffic Light
Red
Yellow
Green
State
Transition
Event
Start
62. Transitions
event [guard] | action
xx yy
The event that
triggers the
transition
Conditions that
must be met for
the transition to
take place
The action that
takes place when
the transition is
taken
63. Initial and Final States
īAn example:
At Work go home At Home
go to work
die die
70. States of Garment (Garments system)
Garment
ordered
Material
ordered
Material
delivered
Marked out for
cutting
Sewn
Marked out for
sewing
Cut
Marked out for
finishing
Finished
Deleted
71. 71
State Diagrams
īA state diagram describes the behaviour of a system,
some part of a system, or an individual object.
īAt any given point in time, the system or object is in a
certain state.
ī Being in a state means that it is will behave in a specific way in
response to any events that occur.
īSome events will cause the system to change state.
ī In the new state, the system will behave in a different way to
events.
īA state diagram is a directed graph where the nodes are
states and the arcs are transitions.
72. Using Microsoft Visio
72
īVisio can be used to draw UML diagrams
īIt is component of Microsoft Office
73. Using Microsoft Visio (continued)
Available Sets of Shapes in the UML Collection
īActivity Diagrams
īCollaboration Diagrams
īComponents
īDeployment Diagrams
īSequence Diagrams
īState Diagrams (Statecharts)
īStatic Structures (shown) â include Packages and Classes
īUse Case Diagrams
73
74. Using Microsoft Visio (concluded)
74
UML symbols can be
displayed as icons with names
or icons with descriptions
Both forms of display for the
Use Case shape set are shown
Now, on to the demo!
75. 75
state
start state
stop state
transition from one state to
another
self-transition (no
change of state)
event [guard] / action transition label (each of the three
parts is optional)
76. The Inheritance Mechanism
īMeans of deriving new class from existing classes, called
base classes
īReuses existing code eliminating tedious, error prone task
of developing new code
īDerived class developed from base by adding or altering
code
77. Multiple Inheritance
īA derived class with several base classes is known as multiple inheritance
īMultiple inheritance permits a class to have more than one super class and
to inherit features from all parents.
ī We can mix information from 2 or more sources.
īThis is a more complicated from of generalization than single inheritance.
īThe advantage of multiple inheritance is greater power in specifying classes
and an increased opportunity for reuse.
īThe disadvantage is a loss of conceptual and implementation simplicity.
78. Credit Cards - Single Inheritance
Same basic features
Each is a little different
79. Voice Mail - Multiple Inheritance
Voice mail has features
of both mail and phone
80. What Is A Constraint
īA condition or restriction (a Boolean expression) expressed in natural
language text or in a machine readable language for the purpose of declaring
some of the semantics of an element
īSome are predefined in UML (âxorâ), others may be user-defined
īOCL (Object Constraint Language) is a predefined language for writing
constraints
81. 81
Constraints
īThese are functional relation between entities of an object
model.
īEntity includes objects, classes, attributes, links and
associations.
īA constraint restricts the values that entities can assume.
īSimple constraints may be placed in object models and
complex may be in functional model.
The names of n-ary associations should contain the names of all the classes, e.g. âAdvisor advises Student in Majorâ.
RSM Implementation Note: the use of a note to express the constraint is optional in UML. For instance, it should be possible to draw a dashed line with the label xor between the Account-Person and Account-Corporation associations. In RSM, the use of the note symbol is imposed.
RSM has a built-in OCL editor with completion lists. The 2 examples on the right were written using this editor.