1 Chapter 12 Visibility Chapter 18 in Applying
1 Chapter 12: Visibility Chapter 18 in Applying UML and Patterns Book.
2 Overview è What is Visibility ? è The visibility between objects. è Four Kinds of Visibility: 1. 2. 3. 4. Attribute Pattern Local Global
3 What is Visibility? è What is Visibility? Visibility is the ability of one object to see or have reference to another. è When is Visibility necessary? To send a message from one object to another, the receiver object must be visible to the sender, so the sender has to have a pointer or reference to the receiver. è Example: If A sends messages to B, which must be visible to which? B is visible to A means A can send a message to B. Some say that "B is an acquaintance of A".
4 Visibility between Objects
5 Visibility è Visibility is related to the scope: Is one resource (such as an instance) within the scope of another? è The motivation to consider visibility: For an object A to send a message to an object B, B must be visible to A.
6 Four Kinds of Visibility è How Visibility can be achieved from Object A to Object B: 1. Attribute visibility - B is an attribute of A. 2. Parameter visibility - B is a parameter of a method of A. 3. Local visibility - B is a local object in a method of A. 4. Global visibility - B is in some way globally visible.
7 1. Attribute Visibility è è Attribute visibility from A to B exists when B is an attribute of A. § Relatively permanent visibility because it persists as long as A and B exist. § Common form of visibility. Example: public class Register { … private Product. Catalog; … }
8 1. Attribute Visibility A Register instance may have attribute visibility to a Product. Catalog.
9 1. Attribute Visibility
10 2. Parameter Visibility è Parameter visibility from A to B exists when B is passed as a parameter to a method of A. § Relatively temporary visibility because it persists only within the scope of the method. § The 2 nd most common form of visibility in the OO systems.
11 2. Parameter Visibility Within the scope of the make. Line. Item method, the sale has parameter visibility to Product. Specification.
12 2. Parameter Visibility è It is common to transform parameter visibility into attribute visibility.
13 2. Parameter Visibility
14 3. Local Visibility è Local visibility from A to B exists when B is declared as a local object within a method of A. § Relatively temporary visibility since it persists only within the scope of the method.
15 3. Local Visibility è è There are two common means by which local visibility is achieved: § Create a new local instance and assign it to a local variable. § Assign the returning object from a method invocation to a local variable. A variation of this method does not explicitly declare a variable, but one implicitly exists as the result of a returning object from a method invocation. Example: an. Object. get. Another. Object. do. Something();
16 4. Global Visibility è Global visibility from A to B exists when B is global to A. § Relatively permanent visibility since it persists as long as A and B exist. § The least common form of visibility in OO Systems.
17 Example
18 Adding Navigability and Dependency Relationships
19 Visibility in the UML è Public: Any outside classifier with visibility to the given classifier can use the feature; specified by pre-pending the symbol “+”. è Protected: Any descendant of the classifier can use the feature; specified by pre-pending the symbol “#”. è Private: Only the classifier itself can use the feature; specified by pre-pending the symbol “-”.
- Slides: 19