01.01.2015 Views

UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory

UML Weekend Crash Course™ - To Parent Directory

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Session 9—Modeling the Static View: The Class Diagram 97<br />

tendency to let numeric attributes default to zero. If the application ever attempts<br />

to divide using this value, you will have to handle resulting errors that could have<br />

been avoided easily with the use of a default.<br />

Constraints: Constraints express all the rules required to guarantee the integrity of<br />

this piece of information. Any time another object tries to alter the attribute value,<br />

it must pass the rules established in the constraints. The constraints are typically<br />

implemented/enforced in any method that attempts to set the attribute value.<br />

The constraint notation brackets appear throughout <strong>UML</strong> diagrams to identify<br />

any and all additional information that helps clarify the intent of the<br />

Note modeling element. Place any text in the constraint brackets that is required<br />

to explain the limitations to be imposed on the implementation of the modeling<br />

element.<br />

Class level attribute (underlined attribute declaration): Optional. Denotes that<br />

all objects of the class share a single value for the attribute. (This is called a static<br />

value in Java.)<br />

Creating an attribute specification<br />

Table 9-1 shows you how to create a sample attribute definition for a company name. The<br />

field has to handle characters and punctuation marks commonly found in company names,<br />

but you’re limited to 30 positions. There is a no default value, but you want valid display<br />

data, so you must initialize the field to spaces.<br />

Table 9-1<br />

Creating an Attribute Specification<br />

Attribute Element Description<br />

Create an attribute name<br />

Add the attribute data type<br />

Add the attribute’s default value, if any<br />

Attribute Element Example<br />

company<br />

company:character<br />

company:character = spaces<br />

Set the constraints on the attribute value. For company:character = spaces {1 to 30<br />

this example, first identify the field length. characters}<br />

Next identify the types of data that can be used company:character = spaces {1 to 30<br />

in the attribute. Add this information within characters including alphabetic,<br />

the brackets.<br />

spaces, and punctuation characters;<br />

no special characters allowed}<br />

Set the attribute visibility (designate private - company:character = spaces {1 to 30<br />

visibility with a minus (-) sign in front of characters including alphabetic, spaces,<br />

the attribute).<br />

and punctuation characters; no special<br />

characters allowed}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!