What Is Class Diagram
What Is Class Diagram
What is a Class
A description of a group of objects all with similar roles in the system,
which consists of:
Structural features (attributes) define what objects of the class
"know"
Represent the state of an object of the class
Are descriptions of the structural or static features of a
class
Behavioral features (operations) define what objects of the class
"can do"
Define the way in which objects may interact
Operations are descriptions of behavioral or dynamic features
of a class
Class Notation
A class notation consists of three parts:
1. Class Name
The name of the class appears in the first partition.
2. Class Attributes
Attributes are shown in the second partition.
The attribute type is shown after the colon.
Attributes map onto member variables (data members) in code.
3. Class Operations (Methods)
Operations are shown in the third partition. They are services
the class provides.
The return type of a method is shown after the colon at the
end of the method signature.
The return type of method parameters is shown after the colon
following the parameter name.
Operations map onto class methods in code
Class Relationships
A class may be involved in one or more relationships with other classes. A
relationship can be one of the following types: (Refer to the figure on
the right for the graphical representation of relationships).
Relationship Type Graphical Rep
Inheritance (or Generalization):
Represents an "is-a" relationship.
An abstract class name is shown in italics.
SubClass1 and SubClass2 are specializations of Super Class.
A solid line with a hollow arrowhead that point from the child to
the parent class
Simple Association:
A structural link between two peer classes.
There is an association between Class1 and Class2
A solid line connecting two classes
Aggregation:
A special type of association. It represents a "part of" relationship.
Class2 is part of Class1.
Many instances (denoted by the *) of Class2 can be associated with
Class1.
Objects of Class1 and Class2 have separate lifetimes.
A solid line with an unfilled diamond at the association end
connected to the class of composite
Composition:
A special type of aggregation where parts are destroyed when the whole is
destroyed.
Objects of Class2 live and die with Class1.
Class2 cannot stand by itself.
A solid line with a filled diamond at the association connected to
the class of composite
Dependency:
Exists between two classes if the changes to the definition of one
may cause changes to the other (but not the other way around).
Class1 depends on Class2
A dashed line with an open arrow
Relationship Names
Names of relationships are written in the middle of the association
line.
Good relation names make sense when you read them out loud:
"Every spreadsheet contains some number of cells",
"an expression evaluates to a value"
They often have a small arrowhead to show the direction in which
direction to read the relationship, e.g., expressions evaluate to
values, but values do not evaluate to expressions.
Relationship - Roles
A role is a directional purpose of an association.
Roles are written at the ends of an association line and describe
the purpose played by that class in the relationship.
E.g., A cell is related to an expression. The nature of the
relationship is that the expression is the formula of the
cell.
Navigability
The arrows indicate whether, given one instance participating in a
relationship, it is possible to determine the instances of the other class
that are related to it.
The diagram above suggests that,
Given a spreadsheet, we can locate all of the cells that it
contains, but that
we cannot determine from a cell in what spreadsheet it is
contained.
Given a cell, we can obtain the related expression and value, but
given a value (or expression) we cannot find the cell of which
those are attributes.
Visibility of Class attributes and Operations
In object-oriented design, there is a notation of visibility for
attributes and operations. UML identifies four types of
visibility: public, protected, private, and package.
The +, -, # and ~ symbols before an attribute and operation name in a
class denote the visibility of the attribute and operation.
+ denotes public attributes or operations
- denotes private attributes or operations
# denotes protected attributes or operations
~ denotes package attributes or operations
Multiplicity Example
Requirement: A Student can take many Courses and many Students can
be enrolled in one Course.
In the example below, the class diagram (on the left), describes
the statement of the requirement above for the static model while
the object diagram (on the right) shows the snapshot (an instance of
the class diagram) of the course enrollment for the courses Software
Engineering and Database Management respectively)
Related Links
Product
Features
Editions
Try Now
Pricing
Visual Paradigm Online
Support
Forums
Request Help
Customer Service
Learn
Community Circle
Know-how
Demo Videos
Tutorials
Documents
About Us
Visual Paradigm
Newsroom
YouTube Channel
Academic Partnership
@2020 by Visual Paradigm. All rights reserved.
Legal
Privacy statement