Visual Introduction to UML for Object-Oriented Design
About UML
UML is a standard maintained by the Object Management Group. UML has its own terminology that is independent of implementation languages such as Java and C#. UML calls pieces of information stored in instances of a class attributes rather than variables. UML calls a class's encapsulations of behavior operations, rather than functions, procedures, methods, or subroutines.
.NET's concept of properties do not directly match anything in UML. If a class has a property named Color, you would draw it in a UML diagram with operations named GetColor and SetColor.
Classes
UML uses a few different kinds of diagrams. This article will focus on class diagrams. A class diagram is a diagram that shows classes, interfaces, objects, and their relationships. The most basic element of a class diagram is a class. Figure 1 shows many of the features that a class can have in a class diagram.
Figure 1: An Example of a Class
Classes are drawn as rectangles. The rectangles may be divided into two or three compartments. The class rectangle shown in Figure 1 has three compartments. The top compartment contains the class's name. The middle compartment lists the class's attributes. The bottom compartment lists the class's operations.
The symbols that precede each attribute and operation are visibility indicators. The possible visibility indicators and their meanings are as follows:
Symbol | Name | Description |
---|---|---|
+ | Public | Unrestricted access |
# | Protected | Access only by the containing class or derived types (children) |
- | Private | Access restricted to the containing class |
UML does not have any simple way of indicating Friend variables or functions.
The attributes in the middle compartment are shown as the following:
visibilityIndicator name : type
Therefore, the two attributes shown in the class in Figure 1 are private. The name of the first attribute is instance and its type is KeyManager. The name of the second attribute is prevKey and its type is Key.
Although not shown in Figure 1, an initial value can be indicated for an attribute by following the attribute's type with an equals sign and the value, like this:
shutDown:Boolean = false
The operations in the bottom compartment are shown as:
visibilityIndicator name ( formalParameters ) : returnTypeThe GetInstance operation shown in Figure 1 returns a KeyManager object. The synchKey operation shown in the class in Figure 1 does not return any result.
A formal parameter of an operation consists of a name and a type like this:
AddToken(token:String)
If an operation has multiple parameters, commas separate them:
DisplayTokenList (tokenList:ArrayList, separator:String)
Formal parameters may each be preceded by one of the words in, out, or inout like this:
GetInfo(inout status:StatusCode, out msg:string):Boolean
Page 1 of 6
This article was originally published on December 12, 2008