Class Diagram
Class Diagram
The main building block of a class diagram is the class, which stores and manages information in
the system.
Each class is drawn by using three part-rectangles with the class’s name at the top, attributes
in the middle, and methods (also called operations) at the bottom.
The attributes of a class and their values define the state of each object that is created from the
class, and the behavior is represented by the methods.
Attributes
Person class in Figure 14-15 contains the attributes lastname, firstname, address, phone,
birthdate, and age.
Derived attribute is age. Because it can be calculated from birth day attribute. Therefore, it is
not stored. Derived attributes are indicated by placing a slash (/) in front of the attribute’s
name.
Visibility
Visibility relates to the level of information hiding to be enforced for the attribute.
public (+) - not hidden from any other object. As such, other objects can modify their value.
protected (#) - hidden from all other classes except its immediate subclasses.
private (-) - hidden from all other classes. The default visibility for an attribute normally is
private.
Operations
Operations are actions or functions that a class can perform.
The functions that are available to all classes (e.g., create a new instance, return a value for a
particular attribute, set a value for a particular attribute, or delete an instance) are not explicitly
shown within the class rectangle.
Only those operations that are unique to the class are included, such as the “terminate” and
“make offer” operations in Figure 14-15 are shown in the rectangle.
These operations are displayed with parentheses ().
Operations should be shown with parentheses that are either empty, or filled with some value
which represents a parameter that the operation needs for it to act.
As with attributes, the visibility of an operation can be designated as public, protected, or
private. The default visibility for an operation is normally public.
There are three kinds of operations.
Constructor
Query
Update
constructor operation
It creates a new instance of a class.
For example, the vehicle class may have an operation called insert () that creates a new vehicle
instance. Because an operation available to all classes (e.g., create a new instance) is not shown
on class diagrams.