Escolar Documentos
Profissional Documentos
Cultura Documentos
INFORMATION SYSTEMS
2
What is object oriented
a) Identity:
• Identity means that data are separated into
distinguishable entities – objects
• Each object has its own identity
(2 objects might be different in spite of
identical values of all attributes (name, size,...)
• Objects might be concrete as well as abstract
Examples:
3
Variable name address
Credit 20030056
Debt 12365478
Account 96385274
table
b) Classification:
4
Case Objects Case Class
Attributes
height
width
Abstract into depth
color
Operace
store
fill
repair
Abstract into
Operations
fill
empty
clean
5
c) Polymorphism
• The same operation can behave differently in
different classes
E.g. the MOVE operation is different for a horse
and rook in the chess game.
• A specific implementation of operation at a
certain class is called a method.
• An operation can be implemented by more than
one method (because of polymorphism).
d) Inheritance
• Sharing of attributes and operations among
classes at a hierarchical principle.
• A superclass contains general information that
subclasses refine.
• Every subclass inherits all features of its
superclass and adds its own unique features.
• This principle is one of basic advantages of the
OO approach which considerably reduces
repetitions in a design.
What is Object Oriented development
• Essence of the OO approach is to distinguish and
to order application domain concepts (and not a
final expression by a programme).
• Model is a tool to understand and describe
reality.
6
Life-cycle phases of the OO metodology:
1. System conception
• System development begins with a problem
formulation.
2. Analysis
• Rising from a problem formulation – building a
real world model (significant features).
• Model is a concise precise abstraction of what
the desired system must do (not how it will be
done).
• It should not contain implementation decisions.
• Analysis model has two parts:
- Domain model (real world objects)
- Application model (visible to the user).
2. System design
• An overall architecture and its principles.
• Decomposition into subsystems.
3. Class design
• Adds (implementation) details to analysis models
• The focus is the data structures and algorithms of
individual object classes.
4. Implementation
• Object classes and their relationships are
converted to a programming language, database
and hardware implementation.
7
Three models
1. Class model
• Static structure of objects and their relationships.
3. Interaction model
• Cooperation of objects in a system.
8
Object modeling
9
Objects and classes
• Object is a subject of our interest in a system.
• All objects have identity and are distinguishable.
• One object = instance.
• Object class describes a group of objects with
similar features (attributes), common behaviour
(operations), same associations with other
objects
e.g.: person, factory, animal, process,....
• Objects and classes occur as nouns in a problem
description.
• Objects in a class share a common semantic
purpose (which is superior to requirement of
same attributes and behaviour)
e.g.: a barn and a horse have same attributes
age and cost – they yet can belong to different
classes.
• By grouping objects into classes we gain several
advantages. For example:
Common definitions are stored only ones for a
class instead for each instance,
Operations are described ones for a class –
possibility to reuse a code.
10
Class diagrams
• A tool for accurate and easy expression of an
object model. Two types of object diagrams in
UML:
Attributes
• Attributes describe data features of an object
• Attributes are introduced in the second part of a
class icon, separated from a class name by a
horizontal line.
11
• A class model doesn’t require explicit object
identifiers (each object is implicitly identified by
its own identity).
• Don’t confuse internal (programming) identifiers
with real attributes.
Person
personID_: ID
name: string
age: integer
Wrong!
12
• As a consequence of polymorphism, same
operation can hold for a number of various
classes where it can have various forms.
E.g. PRINT operation for classes FILE binary or
ASCII.
13
Summary of the object class notation
ClassName
atr1: data type 1 = init.value 1
atr2: data type_2 = init.value 2
oper1 (list of_arguments 1): result1
oper2 (list of_arguments 2): result2
14
• Each association in a class diagram corresponds
to a set of links in an instance diagram similarly
as an object class corresponds to a set of objects.
• UML notation pro association and link is a line
connecting classes or instances.
• Association and link names are typed in italics.
Link name is underlined.
• The name can be omitted if it is single and clear.
Example:
HasCapital
Country City
name name
Class diagram
HasCapital
Italy:Country Rome:City
name=”Italy” name=”Rome”
HasCapital
France:Country Paris:City
name=”France” name=”Paris”
HasCapital
Russia:Country Moscow:City
name=”Russia” name=”Moscow”
Instance diagrams
15
Cardinality and Multiplicity
• Multiplicity specifies how many instances of one
class may relate to a single instance of an
associated class.
• Multiplicity constrains the number of related
objects. Cardinality is a number of elements that
are actually in a collection.
• In UML multiplicity is indicated by a symbol at
the ends of association lines.
Symbols: Meaning:
1:
1 IsMarriedWith 0..1
Man Wife
0 or 1
1 Has 1..*
Book Copy
1 or many
vícvíce
1 Contains 8..20
Group Student
8 to 20
16
Association classes
• An association class is simultaneously an
association and also a class.
• Attributes can describe feature of an association
similarly as they describe features of a class.
* *
F ile User
A c c e s s ib le F o r
a c c e s s R ig h t
0..1 M anages *
boss em plyee
qualification
17
* *
User WorkStation
Authorisation
e
priority
accessRights
startingWorks
* homeFolder
0..1
Folder
Role names
• Role is one end of an association.
• Binary association has two roles each of them
can have a name.
• A role name uniquely identifies one end of an
association. Role names are usually nouns.
• Role names can substitute or supplement
association names.
• Role names are compulsory for an association of
two objects of the same class (see example
PERSON).
18
Person WorksFor Company
name
birthDate address
name
changeAddress employee employer
changeJob
container
19
{ordered}
PCscreen Window
1 VisibleAt *
{sequence}
Itinerary Airport
* *
20
Qualification
• Qualified association puts to relationship two
object classes and a qualifier.
• Qualifier is a special attribute which effectively
reduces multiplicity of an association.
• We can qualify 1:many and many:many
associations.
1 *
Folder File
1 0..1
Folder FileName File
21
Aggregation
• Aggregation is a special type of association, not
a new concept.
• Aggregation is an object relationship of a type
“part-assembly”.
• Symbol of aggregation is an association line with
a “diamond” at a side of assembly.
• Aggregation can have arbitrary number of levels.
Microcomputer
1..* 1 1 1
22
Composition
• A special case of aggregation for which two
limitations hold:
- Part can belong to only one assembly
- Part disappears by disappearing of assembly
• A solid diamond is a graphical symbol of a
composition
23
• Generaliation is the “Ia a” relationship, because
each of a subclass is also an instance of all
superclasses.
• State of instance contains attribute values of all
ancestors.
• Each subclass not only inherits all features of its
ancestors, but it also adds its own specific
attributes and operations.
E.g. Pump adds an attribute flowRate, which
other types of Equipment don’ share.
• Notation for generalisation is a small triangle
connecting a superclass with its subclasses.
• Each object inherits features from one class in
every generalisation level.
• Discriminator is an optional name indicating
which aspect of the system is abstracted by a
particular generalisation. It is placed next to the
small triangle icon.
• Only one aspect can be abstracted in at a time.
E.g. a Vehicle class can be abstracted according
to a type of engine or operational environment..
• It is not suitable to organize generalisation to
excessive many levels, it is confusing.
2-3 levels is OK, 5 is already too much.
24
Equipment
cost
name
weigth
producer
EquipmentType
PumpType
25
Overriding rules
• A subclass can override a superclass feature by
defining a feature with the same name.
E.g.: operation ROTATE is a standard one for
displaying geometric figures. It could be a null
operation for a CIRCLE class.
• We can suppress original values of attributes and
methods of operations. But a signature, a form of
a feature, mustnot be suppressed.
• Features cannot be suppressed in a way to
become inconsistent with a signature or meaning
of originally inherited feature.
Navigation of class models
• So far we have shown how to express an
application structure.
• We can also express how to navigate among
classes.
• We can navigate manually or to navigation
expressions.
• Example:
Let us consider a simple model of credit card
accounts
26
PostAddress CreditCardAcc Institution
1 * 0..1 1
a accountN n
address maxCredit name
telNumber currentBalanc address
ee telNumber
* statemDate
1
* accountOwner 0..1
Customer Statement 0..1 Transaction
1
transactionN
name dueDate transactionDate
amount purpose
minPayment amount
1
Merchant
name
27
• UML contains an OCL (Object Constraint
Language), which can express the above
questions.
28
• Simple association:
Syntax:
source object dot role of target object
or: target object
Ex.: aCreditCardAcc.PostAddress
29
• In OCL, traversal from an object through a single
association yields a singleton or a set (or a bag, if
association has an annotation {bag} or {sequence}.
• Set is a collection of elements without
dupplicates, bag is a collection of elements with
dupplicates allowed.
Example, how OCL expression yields a bag:
OwnsStock
PostAddress Person Company
address * * name * * name
:PostAddress
address=“AA“ Jim:Person
name=“Jim“
:PostAddress
address=“BB“ IBM:Company
John:Person
name=“John“ name=“IBM“
:PostAddress
address=“CC“ Ann:Person
name=“Ann“
:PostAddress
address=“DD“
30
Examples of OCL expressions
Let us use OCL to answer questions to the credit
card:
- What transactions occurred for a credit card
within a time interval?
aCreditCardAcc.Statement.Transaction ->
select(aStartDate <= transactionDate and
transactionDate <= aEndDate)
- What volume of transactions was handled by an
institution last year?
aInstitution.CreditCardAcc.Statement.Transaction
-> select(aStartDate <= transactionDate and
transactionDate <= aEndDate).amount -> sum()
- What customers paid at a merchant by any kind
of credit card?
aMerchant.Purchase ->
select(aStartDate <= transactionDate and
transactionDate <= aEndDate).Statement.
CreditCardAcc.PostAddress.Customer -> asSet()
- How many credit card accounts does a customer
currently have?
aCustomer.PostAddress.CreditCardAcc ->size()
- What is the total maximum credit for a customer
for all accounts?
aCustomer.PostAddress.CreditCardAcc.maxCredit
-> sum()
31
Metadata
• Metadata are data, which describe (define) other
data.
• Examples of metadata: class definition, general
models, catalogues of components,
dictionaries,…
Example of relationship between data a metadata:
CarModel PhysicalCar
Popisuje
modelName serialNumber
year color
1 *
basicPrice accessories
* *
1 manufactucer 1 owner
Company Person
32
Packages
• Split large models into smaller parts –
packages, in order to improve understanding.
• A package is a group of elements (classes,
associations, generalizations and lower level
packages) with a common theme.
• Packages create a tree, where a level of
abstraction increases towards the root.
• Packages are denoted by a box with a tab.
PackageName
33
Practical tips
• First we should understand a problem on hand.
• Try to keep model simple.
• Carefully choose names; descriptively,
unambiguously (it is difficult).
• Do not hide pointers in object as attributes.
Instead, model them as associations.
• Do not try for perfectness in multiplicity too
early. Start with considering multiplicity of „1“.
• Beware of repeated use of the same class. Role
names can help.
• Do not collapse association attributes into a
class.
• Use qualified associations, whenewer possible.
• Avoid deeply nested generalizations.
• Don’t be surprised if our class model still needs
corrections. Let others to evaluate our model.
• Always document our class models.
• Don’t try to use all available instruments. Choose
only those which are helpful to given purpose.
34
Dynamic modeling
35
Events
• An event is something which happens in a time
instant.
Ex.: user pushed a mouse button,
arrival of flight 321 from Rome.
• An event has no duration.
• Events may logically preceed or follow other
event, or two evevnts may be independent.
Ex.: Event Landing of flight 321 from Rome must
be preceded by an event Departure of flight 321
from Rome.
Event Landing of flight 321 from Rome can occur
independently to the event Departure of flight
456 from Melbourne.
• Two events which are causally unrelated are
called concurrent. They have no effect on each
other.
• Both normal and error situations belong to events
– depending on our interepretation.
• The time at which an event occurs is its implicit
attribute.
• Events are of several types: signal events, change
events and time events.
36
Signal events
• Signal event is an explicit one-way transmission
of information from one object to another one.
• Signal event is sending or receipt of a signal (we
are usually more concerned about a receipt).
• Each signal event has a unique occurrence, but
we group them to signal classes and give them a
name (to express a common structure and
behavior).
Ex.: Flight 321 from Rome landed
Flight 765 from London landed
are instances of event class Flight landed.
• Some signal events are a simple occurrence but
majority of event classes has attributes.
Ex.: Flight landed has attributes: airlines, flight
number, city, date.
• UML notation is a keyword «signal» above the
signal class name
«signal» «signal»
FlightLanded MouseButtonPressed
airlines button
flightNumber position
city
date
37
• Attributes are shown (eligibly) in brackets
following an event class name.
Ex.: MouseButtonPressed(button, position)
FlightLanded(airlines, flightNumber, city, date)
StringEntered(text).
Change events
• Change event is caused by satisfaction of a
boolean expression – an event happens when
value of expression changes from FALSE to
TRUE.
• UML notation is a keyword when followed by a
Boolean expression in brackets
Ex.: when(room Temperature<startHeating)
when(room Temperature<startCooling)
when(bateryVoltage<lowerLimit)
Time events
• Time event is caused by reaching an absolute
time or after a time interval was expired.
• UML notation for an absolute time is a keyword
when followed by a time expression in brackets,
for interval a keyword after (length of interval)
Např.: when(date=24.12.2008)
after(10 seconds).
38
States
• State is an abstraction of attribute values and
object links.
• Values are grouped together into states according
to the gross behaviour of objects.
Ex. A bank is either solvent or insolvent.
• In defining a state we ignore attributes, which do
not affect the behaviour of the object.
• Object can have a finite number of states and it
can move through one or more states during its
lifetime.
• State defines a response of the object at input
events.
• Object in a given state reacts only at certain
events and ignores the rest.
• Events represent time instants, states represent
time intervals.
Ex.: After the receiver is lifted and before we dial
the first digit, the phone line is in state Dial tone.
• State of object depends on the previous sequence
of events. The past events are often hidden by
the next event.
39
Ex.: events, which occurred before lifting a
receiver, have no effect on a future behaviour of
a phone line (are forgotten).
• Events and states are in a dual relationship: an
event separates two states and a state separates
two events.
time
40
• State can be expressed in many different ways:
Example:
State: An alarm clock rings
Description: An alarm clock rings in order to
indicate target time
Sequence of events, leading to the state:
switch alarm on
no action containing switching alarm off
actual time=target time (AT = TT)
Conditions which characterize the state:
alarm switched on and
TT ≤ AT≤TT+20 sec. and
no button pressed after TT.
Events received in the state (table
stimuli/reactions):
Event action next state
AT = TT+20 switch alarm off normal
press any button switch alarm off normal
41
State diagrams
• State diagram (SD) shows relationship of events
and states.
• When an event occurs, next state depends on this
event and a present state.
• Change of a state caused by event is transition.
• Nodes in SD are states and oriented links
(arrows) are transitions marked by event names.
• Notation:
• State: Oval with optionally inscribed name.
• Transition: Arrow (from present to next state).
Text next to the arrow is an event name.
• Initial state: solid circle.
• Terminal state: “Bulls eye”.
• SD describes behaviour of a single object class.
• Because all objects of the same class have the
same behaviour (by definition), they all share the
same SD.
• Dynamic (state) model is a collection of state
diagrams of all objects which mutually affect
each other by means of shared events.
• Aktivation of transition leading to a change of
state is called fireing of a transition.
42
Phone line
onHook onHook
Idle
offHook
DialTone time-out
Time-out
digit digit
time-out
Dialing Message
invalid n.
busy
BusyTone valid number
Connecting
connected
Ringing
calledPhoneAnswers
Connected
callerHangsUp
messageDone
Disconnected
start checkmate
White’s turn
Black wins
white black
moves moves stalemate
Draw
Black’s turn
checkmate White wins
43
Conditions
• Condition is a Boolean function of object values.
Ex.: “temperature is below a freezing point”
• Condition holds in a time interval (in contrast to
an event, which has no duration).
Ex.: “It was freezing since Dec. 5th 2003 till
Jan. 3rd 2004”.
• Condition can serve as a guard on transitions. (It
is shown as a Boolean expression in brackets
next to the event name).
• Transition is fired only in a case, when condition
is satisfied at a moment when event occurred. It is
not fired if condition is satisfied later.
Example: Traffic lights at an intersection
time-out (cars in N/S
left lanes)
N/S straight N/S left
time-out time-out
44
Activities
• Description of object behaviour should show
what object is doing in response to an event.
• Activity is performed as a response to an event
received in a state. Activities are performed on a
transition, at the beginning, end or inside a state.
• Notation: “/ activity name” following a
triggering event name.
45
- Do-activity can be interrupted by an event
received during its execution.
Ex.: a robot which is moving a part can
encounter an obstacle which stops moving.
• Input and output activities are performed at the
beginning or end of a state. Input activity is an
equivalent to the activity at an input transition.
Closed Open
entry/motor off depress entry/motor off
46
- If there is an activity on input transition, this
activity is executed first.
- Input activities are indicated inside a state
symbol and have a form entry/activity name.
- Output activities are indicated inside a state
symbol and have a form exit/activity name.
- If a state is terminated by an output transition,
the output activities are executed first.
- If several activities concern a state, then these
are executed in the following order:
- Activities at input transition
- Input activities
- Do-activities
- Output activities
- Activities at output transition.
- When a do-activity is interrupted, the output
activity is still executed.
- Besides entry and exit also other events and
their activities can occur in a state.
Example:
Closed
shutdown/motor off
47
• Automatic (completion) transition.
- Often the only task of the state is to conduct a
sequential activity.
- A transition is automatically fired after
completing activity if transition is not labelled
by an event name and (eventual) condition
holds.
- Unlabeled transitions are called terminal
transitions.
- If a condition(s) is not satisfied at the terminal
transition(s), then “freezing” in the state
occurs. We should look-out for this possibility.
• Sending signals
- Object can perform an activity by sending a
signal to another object – it is object
interaction.
- Activity send target.S(attributes) sends a signal
S (with given attributes) to a target object.
- If a target is a set of objects, each of them
obtains a separate copy of a signal and each
reacts independently.
- If object can receive signals from several objects
then timing of received signals can influence a
final state – “racing conditions”. Simultaneous
occurrence of two events is never meaningfull in
practice.
48
• Basic UML notation of the state diagrams:
event1(attributes1)[condition1]/ effect
State1 State2
do/ activity1 …
event2/effect
49
Example – vending machine:
VendingM achine
Coins in(am ount)
Collecting m oney
Idle Insert coin/add to balance
cancel/refund coins
select(item ) [ change<0]
[item em pty]
[zůstatek=0]
Checking
do / test item and com pute change
[ change=0] [change>0]
DispenseItem
arm ready
arm ready
pushed
50
Generalization of state
• Generalization is “or” relationship.
• Object in a certain state in a root SD must be in
exactly one state in the nested SDs.
(i.e. it must be in the first or in the second or in
one of the following states).
• States can have sub-states, which inherit all input
transitions of their super-states.
Ex.: A phone-line model can be simplified into
two states: “idle” and “active”.
PhoneLine
offHook
Idle Active
onHook
CarTransmission
push R
default
Neutral Reverse
push N
push F
push N
Forward
stop
stop
51
Generalization of events (signals)
• Events can be arranged into a generalization
hierarchy with inheritance of events attributes.
• Each real event is a leaf of this hierarchical tree.
• Inherited event attributes are listed in the bottom
part of the symbol (box).
«signal»
UserInput
device
«signal» «signal»
MouseButton KeyboardChar
location character
52
Concurence
• Dynamic model describes a set of concurent
objects, each with its SD.
• Objects in a system are inherently concurent and
they can independently change their state.
• SD for an assembly is a set of SDs, one for each
component.
• Aggregation enables to a state (for an assembly),
to be decomposed into orthogonal components
(parts), with a limited interaction amongst them.
• Aggregation is an equivalent of state concurency.
• Aggregated state corresponds to combination of
states of all components.
• Aggregation is “and” relationship.
Aggregated state is one state from the first SD and
one state from the second SD and one state from
every next SD.
53
Car
Ignition
Turn a key to start
[Transmission in Neutral] Release a key
Off Starting On
AutomaticTransmission
R
default
neutral reverse
N
F N
forward
stop
stop
Off On Off On
54
Synchronization of concurent activities
• Sometimes object must concurrently conduct two
or more activities.
• Activity in a SD can be decomposed into a lower
level SD.
• We can also model splitting of control and
merging control of concurrent activities:
Cash dispenser
Practical recommendations
• Not all objects need a state model. ⇒ We shall
build a state diagram only for classes with a
meaningfull dynamic behavior (when object
reacts differently at various events and it has
more than a single state).
• Use only relevant attributes to define a state. SD
neednot use all attributes of the object model.
• Check consistence of shared events in different
SDs, in order that a resulting dynamic model was
correct.
55
• When the state has several input transitions and
these transitions trigger the same activity, use
prefferably entry activity in a state instead of
repeated referring of the activity on a transition.
Proceed analogically for exit activity.
• Beware of conditions on transition, to avoid
„freezing“ of an object in a state.
• Beware of unwanted racing conditions (when a
state receives events from several objects).
• Use nested state diagrams, when the same
transition holds for several states.
• Try to create state models of subclasses
independently from state models of their
superclasses. SD of a subclass focuses at
specific/unique attributes of this subclass.
56