The document describes the key elements of a class diagram in UML including classes, attributes, operations, and relationships. A class represents a set of objects with shared characteristics like attributes and behaviors. Common relationships shown are association, aggregation, and generalization. An example class diagram for a Bank Account class is provided to illustrate these concepts.
2. Introduction
• A class diagram in the Unified Modelling language (UML) is a type of static
structure diagram that describes the structure of a system by showing
• system's classes,
• their attributes,
• operations (or methods), and
• the relationships among objects.
3. Class
•A class is a description of a set of objects that share the same
attributes, operations, relationships, and semantics.
•Graphically, a class is rendered as a rectangle, usually
including its name, attributes, and operations in
separate, designated compartments.
4. Example
Bank Account
Owner : String
Balance : Dollars = 0
Deposit (Amount : Dollars)
Withdrawal (Amount : Dollars)
5. Class Names
•The name of the class is the only required
tag in the graphical representation of a class.
• It always appears in the top-most
compartment.
Class Name
Attributes
Operations
6. Class Attributes
•An attribute is a named property of a
class that describes the object being modeled.
•In the class diagram, attributes appear in
the second compartment just below the
name-compartment.
Person
Name: String
Address: Address
Birth date : Date
SSN : ID
7. Class Attributes (Cont’d)
Attributes can be:
• + public
• # protected
• - private
• / derived
Person
+Name: String
#Address: Address
#Birth date : Date
/ Age : Date
-SSN : ID
8. Class Operations
•Operations describe the class behavior and appear in the third compartment.
Person
Name: String
Address: Address
Birth date : Date
SSN : ID
Eat
Sleep
Work
Play
9. Relationships between Classes
• In a class diagram, it is important to see the relationship between classes.
There are following types of relationships amongst classes
• Association
• Aggregation
• Generalization
10. Association Relationship
• An Association is a connection between classes, showing how one class relates to another.
• The association is shown as a line drawn between the classes.
• An Association Name can be given to the association to clarify the association between two
classes
An association relationship between two classes with role
names
11. Aggregation Relationship
• Aggregation is a special case of association used to model a “Whole to its Parts”
relationship.
• An Aggregate relationship can be thought of as a "Consists Of" relationship, where
the Whole consists of the Parts
Basic Aggregation relationship between class Car and class Wheel
12. Generalization Relationship
• The Generalization relationship indicates that one of the two related classes (the
subclass) is considered to be a specialized form of the other (the super type) and
super class is considered as 'Generalization' of subclass.
• In practice, this means that any instance of the subtype is also an instance of the
super class.
Class diagram showing generalization between one super class and two subclasses