Вы находитесь на странице: 1из 41

Software Design & Architecture

UML : Class Diagram

It is a static structure diagram that describes the


structure of a system by showing the
system's classes, their attributes, and the
relationships between the classes.

The class diagram is the main building block


in object oriented modelling
3

Class Diagram

The classes in a class diagram represent both the


main objects and or interactions in the application
and the objects to be programmed
• A Class diagram is used to display the classes in
your system. It gives you a static picture of the
pieces in the system and relationships between
them.
4

Generic Structure of Class


5

Sample Class
6
7

Visibility of Variables
8
9

Relationships between Classes

Association

Aggregation

Composition

Inheritance
10

Association
It represents a linkage between two classes.
Associations are bi-directional i-e both classes
are involved in a relationship
 The line is drawn from the containing to the
contained class
11

Association Example
12

Multiplicity

Identify how many instance of a class can be initiated


against other class.

Represent cardinality of the class in relationship to


another class.

It represent business constraint which will be


implemented in the software
13

Example
14

Bi-Directional Association Example


15

Association - Multiplicity
16

Multiplicity
17

Uni-Directional Association

 In the diagram below PersonName class know


about Telephone# class but not the other way
around.
18

Relationships between Classes

Association

Aggregation

Composition

Inheritance
19

Aggregation or “ has –a “ relationship


Specialized form of association i-e Weak Association.

Assembling a class from other classes.

Aggregation is a special type of relationship used

to model a "whole to its parts" relationship

Part class is independent from the whole class's

lifecycle.
20

Aggregation
 In an aggregation relationship, the child class instance can
outlive its parent class.

 Child class can be a part of multiple parent classes.

 To represent an aggregation relationship, you draw a solid


line from the parent class to the part class, and draw an
unfilled diamond shape on the parent class's association
end
21

Example
22

Aggregation Example
23

Example
24
25

Example – Aggregation and Multiplicity


26

Composition – Container and Contained classes

It’s a strong association.

It contain Objects that live and die together.

The composition aggregation relationship is just


another form of the aggregation relationship, but the
child class's instance lifecycle is dependent on the
parent class's instance lifecycle
27

Composition Continues....

Another important feature of composition


aggregation is that the part class can only be
related to one instance of the parent class
28

Composition Continues....

Another important feature of composition


aggregation is that the part class can only be
related to one instance of the parent class

It is represented by a filled diamond shape from


child to parent class with association
29

Example of Composition
30

Example of Composition
31

Example
32
33

Windows Operating Systems


34

Aggregation Vs Composition
35

Generalization or “IS-A” relationship


It shows a relationship between super / sub class.

Sub class inherit public and protected elements of super class.

Sub class may override the behaviour of super class.

Super Class and Sub classes are related by drawing Arrow


from sub towards super class.
36

Generalization / Specialization

Common data elements and methods are put

together in super class (Generalization) and

specific data elements are put together in sub

classes (Specialization)
37

Conceptual Generalization
38

Generalization Example

Role

attributes
operations

Faculty Student Staff Visitor


attributes attributes attributes attributes

operations operations operations operations


39

Example
40
41
Poor Generalization Example
(violates the “is a” or “is a kind of” heuristic)

Person
attributes
operations

Arm Leg Head


attributes attributes attributes

operations operations operations

Вам также может понравиться