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.

98<br />

Saturday Morning<br />

In a modeling tool, an attribute definition may appear as a set of fields on a specification<br />

window, or the single line format, or a combination of the two. Regardless of the tool<br />

interface, this set of fields can be a good tool for remembering the types of questions you<br />

need to answer for each piece of information in your model. This data forms the foundation<br />

for your databases, your user interfaces, reporting, and nearly every aspect of your design.<br />

Thoroughness here pays big dividends later.<br />

Modeling an Operation<br />

Objects have behaviors, things they can do and things that can be done to them. These<br />

behaviors are modeled as operations. By way of clarification, the <strong>UML</strong> distinguishes between<br />

operation and method, whereas many people use them interchangeably. In the <strong>UML</strong>, an<br />

operation is the declaration of the signature or interface, the minimum information<br />

required to invoke the behavior on an object. A method is the implementation of an operation<br />

and must conform to the signature of the operation that it implements.<br />

Elements of an operation specification<br />

Operations require a name, arguments, and sometimes a return. Arguments, or input parameters,<br />

are simply attributes, so they are specified using the attribute notation (name, data<br />

type, constraints, and default), although it is very common to use the abbreviated form of<br />

name and data type only.<br />

Note that if you use constraints on an argument, you are constraining the input value,<br />

not the value of the attribute as it resides in the source object. The value in the source<br />

object was constrained in the attribute definition within the class.<br />

The return is an attribute data type. You can specify the visibility of the operation:<br />

private (-) limits access to objects of the same class, public (+) allows access by any object,<br />

protected (#) limits access to objects of subclasses within the inheritance hierarchy (and<br />

sometimes the same package), and package (~) limits access to objects within the same<br />

package. Given these requirements, the following notation is used to define an operation:<br />

visibility operationName ( argname : data type {constraints}, ...) :<br />

return data type {constraints}<br />

Once again, writing this down as a kind of cheat sheet isn’t a bad idea. It will help you<br />

remember all the issues you need to address when defining operations. Here’s the run-down<br />

on each element in this expression.<br />

Operation name: Required. Does not have to be unique, but the combination of<br />

name and parameters does need to be unique within a class.<br />

Arguments/parameters: Any number of arguments is allowed. Each argument<br />

requires an identifier and a data type. Constraints may be used to define the valid<br />

set of values that may be passed in the argument. But constraints are not supported<br />

in many tools and will not be reflected in the code for the operation, at least not at<br />

this point.

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

Saved successfully!

Ooh no, something went wrong!