ITEC1301 Object-Oriented Systems Construction

Download Report

Transcript ITEC1301 Object-Oriented Systems Construction

ITEC1301
Object-Oriented Systems Construction
Lecture Notes #4
1
Instances
In the UML, you can represent instances, especially
objects.
Instance and object are almost the same.
In general, an object is something that takes up space
in the real or conceptual world, and you can do things
to it.
Instances are commonly found in object diagrams.




2
Types and Names
The instance can be an named instance or an
anonymous instance.
The type of actual instance must be a concrete
classifier.
During development, you may have instances with no
associated type.



3
Types and Names
4
Operation and State
5
Object Diagram
With the UML, an object diagram expresses the static
part of an interaction.
An object diagram freezes a moment in time.


6
Object Diagram Example
7
Common Properties and Usages

Object diagrams commonly contain





8
Objects
Links
Object diagrams may contain notes and
constraints.
Object diagrams let you model static data
structures.
Object diagrams let you present one static
snapshot of an system interaction.
More Example
9
Interactions


10
You use interactions to model the dynamic aspect of
collaborations.
A collaboration represents societies of objects playing
specific roles, all working together to carry some
behavior.
Example
11
Interactions




Interactions introduces objects that work together to
carry out some action.
Interactions also introduce messages that are
dispatched from object to object.
You use interactions to model flow of control.
An interaction is similar to an object diagram. In
addition, an interaction introduces a sequence of
messages that may pass along the links.
12
Objects/Roles/Links/Connectors
13
Links and Connectors (2)



In general, a link is an instance of an association.
Wherever a class has an association, there may be a link
between the instances of two classes.
Wherever, there is a link between two objects, one object
may send a message to the other object.
14
Links and Connectors (3)




In most models, we are more interested in prototypical
objects and links rather than individual objects and links.
A prototypical object is a role.
A prototypical link is a connector.
The multiplicity of roles and connectors are relative to
their context.
15
Messages



A message is a communication among objects
that conveys information with the expectation
that activity will ensue.
When you pass a message, an action usually
results on its receipt.
In the UML, you can model several kinds of
messages.





16
Call
Return
Send
Create
Delete
Message Example
17
Messages (2)


The most common kind of messages is the call.
When you call an operation of an object, that operation
must exist and visible in the target class.
18
Sending a Signal



Instead of sending a message, you may send a signal to the
target object
A signal occurs asynchronously.
After sending a signal, the sending object continues its
own execution. The target object independently decides
what to do.
19
Sequencing



When an object passes a message to another object,
the receiving object might in turn send a message to
another object.
This forms a sequence.
A sequence usually causes a nested flow of control.
20
Sequencing (2)

On the other hand, a sequence may cause a flat flow of
control.
21
Sequencing (3)


You may show the actual arguments and return value
along with an operation or signal.
For example
1.3.2 : p := find(“Rachelle”)
22
Representation

You can visualize an interaction in two ways:



By emphasizing the time ordering of message. This diagram is
called a sequence diagram.
By emphasizing the structural organization of roles that send
and receive messages. This is called a communication
diagram.
Both diagrams are kinds of interaction diagram.
 model the dynamic aspects of a system is by
building up storyboards of scenarios

Interaction diagrams commonly contain:


23
Roles or objects
Messages
Communication Diagrams
24
Sequence Diagrams

A sequence diagram emphasizes the time ordering of
messages.
25
Sequence Diagram Example
26
Sequence Diagrams




Sequence diagrams have two features that distinguish
them from communication diagrams.
First, there is the lifeline.
Second, there is the focus of control.
The main content in a sequence diagram is the messages.
27
Structured Control in
Sequence Diagrams
28
Semantic Equivalence


Sequence diagrams and communication diagrams are
semantically equivalent.
As a result, you can take a diagram in one form and
convert it to the other without any loss of information.
29
Sequence Diagram Example
30
Communication Diagram Example
31
Common Uses

You typically use interaction diagrams in two ways.


32
To model flows of control by time ordering (sequence
diagram).
To model flows of control by organization (communication
diagram).
Modeling a Flow of Control


When you model an interaction, you essentially
build a storyboard of the actions that take place
among objects.
To model a flow of control,




33
Set the context for the interaction (a system, subsystem,
class, operation).
Identify objects and their roles.
If drawing a communication diagram, identify links
between objects.
In time order, specify messages from object to object.
Distinguish different kind of messages, as necessary.
Include parameters and return values.
Hints and Tips

A well-structured interaction



34
Is simple and should encompass only those objects that work
together.
Has a clear context.
Is understandable and should be straightforward