Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
12/25/2014
: Register
: ProductCatalog
enterItem
(itemID, quantity)
spec := getSpecification( itemID )
{
public void enterItem( itemID, qty )
{
...
spec = catalog.getSpecification(itemID)
...
}
}
Visibility
Visibility is the ability to an object to see or have a reference to another
object.
It is related to issue of scope: Is one resource (e.g. instance) within
scope of another? Four common ways that visibility can be achieved from
object A to object B are:
Attribute Visibility B is an attribute of A.
Parameter Visibility B is a parameter of a method of A.
Local Visibility B is a (non-parameter) local object in a method of A.
Global Visibility B is in some way globally visible.
The motivation to consider visibility is:
For an object A to send a message to an object B, B must be visible to
A.
For example, to create an interaction diagram in which a message is
sent from a Register instance to a ProductCatalog instance, the
Register must have visibility to the ProductCatalog.
A typical visibility solution is that a reference to the ProductCatalog
instance is maintained as an attribute of the Register.
Visibility
and Class
Diagrams
12/25/2014
1. Attribute Visibility
Attribute visibility from A to B exists when B is an attribute
of A, a common visibility in object-oriented systems.
It is a relatively permanent visibility because it persists as
long as A and B exist.
To illustrate, in a Java class definition, a Register instance
may have attribute visibility to a ProductCatalog, since it is
an attribute (Java instance variable) of the Register
public class Register {
class Register
{
...
private ProductCatalog catalog;
...
}
: Register
: ProductCatalog
enterItem
(itemID, quantity)
spec := getSpecification( itemID )
12/25/2014
2. Parameter Visibility
Parameter visibility from A to B exists when B is passed
as a parameter to a method of A and second most
attribute visibility.
To illustrate, when the makeLineItem message is sent to a
Sale instance, a ProductSpecification instance is passed
as a parameter.
Visibility
and Class
Diagrams
2: makeLineItem(spec, qty)
:Sale
2: spec := getSpecification(id)
2.1: create(spec, qty)
:Product
Catalog
sl : SalesLineItem
12/25/2014
3. Local Visibility
Local visibility from A to B exists when declared as a local object
within a method of A, a third most common visibility after
parameter visibility in object-oriented systems.
It is relatively temporary visibility because is persists only within
the scope of the method.
As with parameter visibility, it is common to transform locally
10
12/25/2014
4. Global Visibility
Global visibility from A to B exists when B is global to A. It is a
relatively permanent visibility because it persists as long as A
and B exist, a least common visibility in object-oriented
systems.
One way to achieve visibility is to assign an instance to a
global variable possible in C++.
The preferred method to achieve global visibility is to use the
Singleton pattern. In software engineering, the singleton
pattern is a design pattern that is used to restrict instantiation
of a class to one object.
This is useful when exactly one object is needed to coordinate
actions across the system. Sometimes it is generalized to
systems that operate more efficiently when only one or a few
objects exist.
Visibility
and Class
Diagrams
11
1: msg()
association
:A
2: msg()
parameter
3: msg()
local
:B
:C
:D
4: msg()
global
:E
12
12/25/2014
Sale
Creation of DCDs
DCDs are usually created in
parallel with interaction diagrams
Example DCD
Figure 11.6 illustrates a partial
software definition of the Register
and Sale classes.
Besides to basic associations and
attributes, the diagram is extended
to illustrate, for example, the
methods of each class, attribute
type information and attribute
visibility and navigation between
objects.
Visibility
and Class
Diagrams
Navigability
Register
Captures
1
date
isComplete : Boolean
1 time
enterItem(...)
makeLineItem(...)
methods; there are parameters, but unspecified
type information
13
14
12/25/2014
abstraction of a real-world
concept which we are
Captures
1
Domain Model
date
1 isComplete : Boolean
time
interested in making a
statement.
Register
...
Design Model
endSale()
enterItem(...)
makePayment(...)
Captures
1
date
isComplete : Boolean
1 time
makeLineItem(...)
software class
Sale
15
P r o d u c tC a ta lo g
P r o d u c tS p e c if ic a t io n
d e s c r ip tio n
p ric e
ite m I D
...
...
...
P a ym e n t
a m o u n t
...
...
S to re
a d d re s s
n a m e
S a le
S a le s L in e Ite m
d a te
is C o m p le te
tim e
q u a n tity
...
...
...
16
12/25/2014
Sale
..
2: makeLineItem(spec, qty)
:Register
makeLineItem(.. )
:Sale
17
...
...
endSale()
enterItem(...)
makeNewSale()
makePayment(...)
getSpecification()
Depiction of accessing
methods
Store
Register
ProductCatalog
addSale(...)
Language-dependent
syntax
Visibility
and Class
Diagrams
description
price
itemID
Payment
amount
...
...
Sale
date
isComplete
time
address
name
Interpretation of
messages to multi-objects
ProductSpecification
SalesLineItem
quantity
becomeComplete()
makeLineItem(...)
makePayment(...)
getTotal()
getSubtotal()
18
12/25/2014
19
ProductCatalog
...
ProductSpecification
description : Text
price : Money
getSpecification(id: ItemID) : ProductSpecification
itemID : ItemID
...
endSale()
enterItem(id : ItemID, qty : Integer)
makeNewSale()
makePayment(cashTendered : Money)
...
Store
Sale
address : Address
name : Text
SalesLineItem
date : Date
isComplete : Boolean
time : Time
quantity : Integer
getSubtotal() : Money
addSale(s : Sale)
becomeComplete()
Payment
makeLineItem(spec : ProdSpecification , qty : Integer)
makePayment(cashTendered : Money)
amount
: Money
getTotal() : Money
...
20
10
12/25/2014
Sale
Register
Navigability is a property
of role that indicates that
it is possible to navigate
uni-directionally across
association from objects
of source target class.
the currentSale
attribute is often
excluded, as it is
implied by the
navigable
association from
Register to Sale.
Captures
endSale()
enterItem(...)
makeNewSale()
makePayment(...)
1 becomeComplete()
makeLineItem(...)
makePayment(...)
getTotal()
Absence of navigability
arrow indicates no
connection from Sale to
Register.
Navigability implies
visibility usually
attribute visibility as in
Figure 11.12.
Visibility
and Class
Diagrams
currentSale : Sale
date
isComplete
time
21
create()
2: create(pc)
:Store
1: create()
:Register
1.1: create()
1.2.2*: add(ps)
pc:
ProductCatalog
:Product
Specification
ps:
ProductSpecification
22
11
12/25/2014
Store
1
23
Uses
address : Address
name : Text
1
1
ProductSpecification
ProductCatalog
addSale(...)
1
Looks-in
Contains
...
1..*
description : Text
price : Money
itemID: ItemID
getSpecification(...)
...
Houses
1
Register
...
Captures
endSale()
enterItem(...)
makeNewSale()
makePayment(...)
1
Describes
Sale
Logs-completed
4
date : Date
isComplete : Boolean
time : Time
1
becomeComplete()
makeLineItem(...)
makePayment(...)
getTotal()
*
SalesLineItem
Contains
quantity : Integer
1..*
getSubtotal()
Payment
Paid-by
1
amount : Money
...
Figure 11.14: Association with navigability adornment and dependency relationships indicating non-attribute
Visibility
and Class
Diagrams
24
12
12/25/2014
Exercises
1. (Group) Information system for a Library
Using the confirmMembership operation contract as a starting hint,
complete the UML collaboration diagram. Annotate every message
with the hint GRASP (Expert, Creator, and so on) and/or other
pattern that justifies it. If you add responsibilities not explicit in the
contract (because you think they are important to fulfill), please
briefly explain these additions.
by Controller
confirmMembership(membershipID)
Visibility
and Class
Diagrams
25
Exercises
Visibility
and Class
Diagrams
26
13
12/25/2014
14