UML Weekend Crash Course⢠- To Parent Directory
UML Weekend Crash Course⢠- To Parent Directory UML Weekend Crash Course⢠- To Parent Directory
Session 9—Modeling the Static View: The Class Diagram 95 Although other diagrams are necessary, remember that their primary purpose is to support the construction and testing of the Class diagram. Whenever another diagram reveals new or modified information about a class, the Class diagram must be updated to include the new information. If this new information is not passed on to the Class diagram, it will not be reflected in your code. The Object diagram The class defines the rules; the objects express the facts. The class defines what can be; the object describes what is. If the Class diagram says, “This is the way things should be,” but the Object diagram graphically demonstrates that “it just ain’t so,” then you have a very specific problem to track down. The reverse is true, too. The Object diagram can confirm that everything is working as it should. Session 13 walks you through an example of applying the Object diagram for just this purpose. Elements of the Class Definition The class symbol is comprised of three compartments (rectangular spaces) that contain distinct information needed to describe the properties of a single type of object. The name compartment uniquely defines a class (a type of object) within a package. Consequently, classes may have the same name if they reside in different packages. The attribute compartment contains all the data definitions. The operations compartment contains a definition for each behavior supported by this type of object. Tip Technically, the UML allows for user-defined compartments as well as the three standard ones, but I’ll leave that as an advanced topic for another book or for your own personal study of the UML specification. Sessions 10 and 11 present the rest of the notations that make up the Class diagram. Modeling an Attribute An attribute describes a piece of information that an object owns or knows about itself. To use that information, you must assign a name and then specify the kind of information, or data type. Data types may be primitive data types supplied by a language, or abstract data types (types defined by the developer). In addition, each attribute may have rules constraining the values assigned to it. Often a default value helps to ensure that the attribute always contains valid, meaningful data.
96 Saturday Morning Attribute visibility Each attribute definition must also specify what other objects are allowed to see the attribute — that is its visibility. Visibility is defined as follows: Public (+) visibility allows access to objects of all other classes. Private (-) visibility limits access to within the class itself. For example, only operations of the class have access to a private attribute. Protected (#) visibility allows access by subclasses. In the case of generalizations (inheritance), subclasses must have access to the attributes and operations of the superclass or they cannot be inherited. Package (~) visibility allows access to other objects in the same package. Note the symbols for each type of visibility. The symbols provide a convenient shorthand and tend to be used instead of the full name. The rules for protected visibility vary a little among programming languages. Check the rules for your particular implementation environment. For example, protected in Java allows objects of classes within the same package to Tip see the value as well. Given these requirements, the following notation is a common way of defining an attribute: visibility / attribute name : data type = default value {constraints} Writing this down as a kind of cheat sheet isn’t a bad idea. It will help you remember all the issues you need to address when defining data. Here’s the run-down on each element in this expression. Visibility (+, -, #, ~): Required before code generation. The programming language will typically specify the valid options. The minus sign represents the visibility “private” meaning only members of the class that defines the attribute may see the attribute. Slash (/): The derived attribute indicator is optional. Derived values may be computed or figured out using other data and a set of rules or formulas. Consequently, there are more design decisions that need to be addressed regarding the handling of this data. Often this flag is used as a placeholder until the design decisions resolve the handling of the data. Attribute name: Required. Must be unique within the class. Data type: Required. This is a big subject. During analysis, the data type should reflect how the client sees the data. You could think of this as the external view. During design, the data type will need to represent the programming language data type for the environment in which the class will be coded. These two pieces of information can give the programmer some very specific insights for the coding of get and set methods to support access to the attribute value. Assignment operator and default value: Optional. Default values serve two valuable purposes. First, default values can provide significant ease-of-use improvements for the client. Second and more importantly, they protect the integrity of the system from being corrupted by missing or invalid values. A common example is the
- Page 67 and 68: 44 Friday Evening In the effort to
- Page 70 and 71: Part II — Saturday Morning Sessio
- Page 72 and 73: SESSION 5 Understanding the Use Cas
- Page 74 and 75: Session 5—Understanding the Use C
- Page 76 and 77: Session 5—Understanding the Use C
- Page 78 and 79: Session 5—Understanding the Use C
- Page 80 and 81: Session 5—Understanding the Use C
- Page 82: Session 5—Understanding the Use C
- Page 85 and 86: 62 Saturday Morning Order Fulfillme
- Page 87 and 88: 64 Saturday Morning What does the
- Page 89 and 90: 66 Saturday Morning For example, th
- Page 91 and 92: 68 Saturday Morning REVIEW The goal
- Page 93 and 94: 70 Saturday Morning Much of this la
- Page 95 and 96: 72 Saturday Morning You reply that
- Page 97 and 98: 74 Saturday Morning Writing a Use C
- Page 99 and 100: 76 Saturday Morning Use Case dialog
- Page 101 and 102: 78 Saturday Morning Table 7-7 The F
- Page 104 and 105: SESSION 8 Identifying the Use Case
- Page 106 and 107: Session 8—Identifying the Use Cas
- Page 108 and 109: Session 8—Identifying the Use Cas
- Page 110 and 111: Session 8—Identifying the Use Cas
- Page 112 and 113: Session 8—Identifying the Use Cas
- Page 114: Session 8—Identifying the Use Cas
- Page 117: 94 Saturday Morning The Class diagr
- Page 121 and 122: 98 Saturday Morning In a modeling t
- Page 123 and 124: 100 Saturday Morning Table 9-2 Cont
- Page 125 and 126: 102 Saturday Morning Operation comp
- Page 128 and 129: SESSION 10 The Class Diagram: Assoc
- Page 130 and 131: Session 10—The Class Diagram: Ass
- Page 132 and 133: Session 10—The Class Diagram: Ass
- Page 134 and 135: Session 10—The Class Diagram: Ass
- Page 136 and 137: Session 10—The Class Diagram: Ass
- Page 138 and 139: Part II — Saturday Morning Part R
- Page 140 and 141: SESSION 11 The Class Diagram: Aggre
- Page 142 and 143: Session 11—The Class Diagram: Agg
- Page 144 and 145: Session 11—The Class Diagram: Agg
- Page 146 and 147: Session 11—The Class Diagram: Agg
- Page 148 and 149: Session 11—The Class Diagram: Agg
- Page 150: Session 11—The Class Diagram: Agg
- Page 153 and 154: 130 Saturday Afternoon or not. Each
- Page 155 and 156: 132 Saturday Afternoon 5. “Any it
- Page 157 and 158: 134 Saturday Afternoon designed to
- Page 159 and 160: 136 Saturday Afternoon Table 12-3 T
- Page 161 and 162: 138 Saturday Afternoon REVIEW The C
- Page 163 and 164: 140 Saturday Afternoon Introducing
- Page 165 and 166: 142 Saturday Afternoon Table 13-1 C
- Page 167 and 168: 144 Saturday Afternoon 28: VendorPr
96<br />
Saturday Morning<br />
Attribute visibility<br />
Each attribute definition must also specify what other objects are allowed to see the<br />
attribute — that is its visibility. Visibility is defined as follows:<br />
Public (+) visibility allows access to objects of all other classes.<br />
Private (-) visibility limits access to within the class itself. For example, only<br />
operations of the class have access to a private attribute.<br />
Protected (#) visibility allows access by subclasses. In the case of generalizations<br />
(inheritance), subclasses must have access to the attributes and operations of the<br />
superclass or they cannot be inherited.<br />
Package (~) visibility allows access to other objects in the same package.<br />
Note the symbols for each type of visibility. The symbols provide a convenient shorthand<br />
and tend to be used instead of the full name.<br />
The rules for protected visibility vary a little among programming languages.<br />
Check the rules for your particular implementation environment. For example,<br />
protected in Java allows objects of classes within the same package to<br />
Tip<br />
see the value as well.<br />
Given these requirements, the following notation is a common way of defining an<br />
attribute:<br />
visibility / attribute name : data type = default value {constraints}<br />
Writing this down as a kind of cheat sheet isn’t a bad idea. It will help you remember all<br />
the issues you need to address when defining data. Here’s the run-down on each element in<br />
this expression.<br />
Visibility (+, -, #, ~): Required before code generation. The programming language<br />
will typically specify the valid options. The minus sign represents the visibility “private”<br />
meaning only members of the class that defines the attribute may see the<br />
attribute.<br />
Slash (/): The derived attribute indicator is optional. Derived values may be computed<br />
or figured out using other data and a set of rules or formulas. Consequently,<br />
there are more design decisions that need to be addressed regarding the handling<br />
of this data. Often this flag is used as a placeholder until the design decisions<br />
resolve the handling of the data.<br />
Attribute name: Required. Must be unique within the class.<br />
Data type: Required. This is a big subject. During analysis, the data type should<br />
reflect how the client sees the data. You could think of this as the external view.<br />
During design, the data type will need to represent the programming language data<br />
type for the environment in which the class will be coded. These two pieces of<br />
information can give the programmer some very specific insights for the coding<br />
of get and set methods to support access to the attribute value.<br />
Assignment operator and default value: Optional. Default values serve two valuable<br />
purposes. First, default values can provide significant ease-of-use improvements<br />
for the client. Second and more importantly, they protect the integrity of the system<br />
from being corrupted by missing or invalid values. A common example is the