Visualizing a Class

Visualizing a Class

Visualizing a Class
4 min read

A class is drawn as a box in UML notation. The class name starts with a capital letter and is placed at the top of the box. If the class name consists of 2 or more words, all the words are joined without spaces, with the first letter of each word capitalized.

Attribute

An attribute is a property of a class. An attribute describes the range of values that may exist in objects of the class. A class may have zero or more attributes. By convention, if an attribute name consists of one word, it is written in lowercase. However, if an attribute name contains more than one word, all the words are joined, with the first word in lowercase and the first letter of each following word capitalized.

Refrigerator

brand

model

serialNumber

capacity

 

UML gives you the option to provide additional information for an attribute. The type of each attribute can be added here. Types that may be added include: string, floating-point number, integer and Boolean. To show the type, use a colon (:) to separate the attribute name from the type. A default value for an attribute can also be added if desired.

Refrigerator

brand              : String=’LG’

model              : String

serialNumber      : String

numberOfDoors     : Integer          

 

Note: The attribute type can also be defined by the developer, such as the values 'solid', 'liquid', or 'gas'

Operation

An operation is something a class can do, or something you (or another class) can do to a class. Like attributes, operation names are also all lowercase if they consist of one word. However, if there is more than one word, all the words are joined, with the first word in lowercase and the first letter of each following word capitalized.

Refrigerator

brand

model

serialNumber

capacity

putInFruit()

takeOutFruit()

turnOn()

 

Just like attributes, we can also provide additional information for an operation by adding the parameters the operation will use in parentheses. One form of operation is a function, whose purpose is to return a value after the operation is run. For such functions, the type and value of the operation's result can be shown.

Recommended for you