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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Return data type: Required for a return value, but return values are optional. The<br />

<strong>UML</strong> only allows for the type, not the name, which is consistent with most programming<br />

languages. There may only be one return data type, which again is consistent<br />

with most programming languages.<br />

Visibility (+, -, #, ~): Required before code generation. The visibility values are<br />

defined by the programming language, but typically include public (+), private (-),<br />

protected (#), and package (~).<br />

Class level operation (underlined operation declaration): Optional. Denoted as<br />

an operation accessible at the class level; requires an instance (object) reference.<br />

Argument name: Required for each parameter, but parameters are optional. Any<br />

number of arguments is allowed.<br />

Argument data type: Required for each parameter, but parameters are optional.<br />

Constraints: Optional. In general, constraints express rules that must be enforced<br />

in the execution of the operation. In the case of parameters, they express criteria<br />

that the values must satisfy before they may be used by the operation. You can<br />

think of them as operation level pre-conditions.<br />

Creating an operation specification<br />

Table 9-2 shows you how to create a sample operation to determine the total amount due on<br />

an order. The total is the sum of all line items less the volume discount. Each line item<br />

amount is the product of the unit price and discount. You need the answer back as a dollar<br />

amount.<br />

Table 9-2<br />

Creating an Operation Specification<br />

Operation Element Description<br />

Name the operation.<br />

Define the arguments/parameters:<br />

All the input information is on the Order object,<br />

so an instance of Order is the only argument.<br />

Name the argument and data type and separate<br />

them with a colon. Try to use argument names<br />

that match the argument type; this makes<br />

referring to the value within the method<br />

easier. The data type in this example is the<br />

user-defined class “Order.” Enclose the<br />

arguments in parentheses.<br />

Operation Element Example<br />

totalOrderAmount<br />

totalOrderAmount (order : Order)<br />

Continued

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

Saved successfully!

Ooh no, something went wrong!