You are on page 1of 15

UML CLASS DIAGRAM

What is a class diagram?


1. The class diagram is a static model that shows the classes and the relationships among classes in the system. 2. class diagrams illustrates classes, interfaces, and their associations. They are used for static object modeling. 3. A Class diagram gives an overview of a system by showing its classes and the relationships among them. Class diagrams display what interacts but not what happens when they do interact.
1 www.mahmoud-a.com

UML CLASS DIAGRAM


What is a class?
1. The main building block of a class diagram is the class, which stores and manages information in the system. 2. A blueprint that an object made from.

what are the contents of the class?


The class contains two major parts: 1. Attributes data members. 2. Operations method members.

www.mahmoud-a.com

UML CLASS DIAGRAM


Example 1:

www.mahmoud-a.com

UML CLASS DIAGRAM


Class diagrams symbols:
Description
Class : represents a person, place, or thing about which the system will need to capture and store information. Attribute: Represents properties that describe the state of an object. Must be named with noun. Method operation: Represents the actions or functions that a object can perform. Must be named with verb. Association: Represents a relationship between multiple classes, or a class and itself. Must be labeled with verb. Multiplicity: Represents the minimum and maximum times a class instance can be associated with the related class instance.
4 www.mahmoud-a.com

symbol
Class name Attributes list Methods list

association name 0..* 1 11 1..* - 0..* 1 m 1..7 4..9 m - n

UML CLASS DIAGRAM


Class diagrams symbols:
Description Aggregation: is a weak whole - part relationship, when an object is part of other object(s). (is part of). Composition: is a strong whole part relationship, when an object is part of another object. If the container (whole) object is destroyed the part object is also destroyed. Generalization inheritance : when a class (subclass) inherits from another class (super class),meaning that the properties and operations of the super class are also valid for objects of the subclass. (is a).
5 www.mahmoud-a.com

Symbol Whole part

Whole

part

super

sub

UML - Class Diagram


Customer

Rental Invoice

Rental Item {abstract}

1..* 1 0..1

1
Checkout Screen DVD Movie VHS Movie Video Game

www.mahmoud-a.com

UML - Class Diagram


Multiplicity Customer Class

Simple Aggregation

Abstract Class Rental Item {abstract}

Rental Invoice

1..* 1
Composition (Dependency)

0..1
Simple Association Checkout Screen

Generalization

DVD Movie

VHS Movie

Video Game

www.mahmoud-a.com

UML CLASS DIAGRAM


Aggregation relationship:
1. the part may be independent of the whole but the whole requires the part. 2. An association in which one class belongs to a collection of classes.

www.mahmoud-a.com

UML CLASS DIAGRAM


Aggregation Examples:
1. A room contains a table. A table is part of a room, if the room destroyed the table remains. contains
Room table

2. Think about a doctors office that has decided to create health care teams that include doctors, nurses, and administrative personnel. As patients enter the office, they are assigned to a health care team that cares for their needs during their visits.

www.mahmoud-a.com

UML CLASS DIAGRAM


Aggregation Examples: 3. Order class is part of order details class. If the order details object destroyed the order object remains. 4. a catalogue object is a collection (aggregation) that consists of many product objects. However, any particular product may appear in more than one catalogue.
contains

catalogue

product

10

www.mahmoud-a.com

UML CLASS DIAGRAM


Composition relationship :

1. Each part object may belong to only one whole object at a time. 2. When the whole object is destroyed, its parts also are destroyed. 3. Whole object is responsible for the creation and destruction of the parts. In native c++ if your objects parts are pointer you need to destroy it using delete keyword, because there is no garbage collector! , unlike java, C# and visual basic.net .
11 www.mahmoud-a.com

UML CLASS DIAGRAM


Composition examples:
1. A building contains a room, a room is part of building, if a building is destroyed the room also destroyed.
building
contains

room

2. A polygon made of point ,if a polygon is destroyed, Point will be destroyed with it.

12

www.mahmoud-a.com

UML CLASS DIAGRAM


Composition examples: 3. Think about product group class which is made up of products, if the product group object deleted the product object within that group will be deleted too.

4. Imagine such a system including a Generic Report class. A Generic Report is composed of four parts Header, Column, Body, and Footer. If a report object is destroyed the parts will be destroyed.

13

www.mahmoud-a.com

UML CLASS DIAGRAM


Lab assignment: 1. Draw class diagram for aggregation example 2. 2. Draw class diagram for composition example 4.

14

www.mahmoud-a.com

UML CLASS DIAGRAM


References:

1. Systems Analysis & Design with UML, 2nd Edition. 2. The object primer agile model driven development with uml 2.

15

www.mahmoud-a.com

You might also like