0% found this document useful (0 votes)
4 views

CSE 1203 03 AdvanceTopicUML

Uploaded by

jummoxchangmha01
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

CSE 1203 03 AdvanceTopicUML

Uploaded by

jummoxchangmha01
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Remove

Wondershare
Watermark PDFelement

CSE 12031

Object Oriented Programming [C++]

Chapter 4:
Advanced Topics-3: UML
Remove
Wondershare
Watermark PDFelement

UML: Unified Modeling Language


What is UML? 2 Benefits of class diagrams
• Class diagrams offer a number of benefits
The Unified Modeling Language (UML) was created to for any organization. Use UML class
forge a common, semantically and syntactically rich diagrams to:
visual modeling language for the architecture, design, • Illustrate data models for information
and implementation of complex software systems both systems, no matter how simple or
structurally and behaviorally. complex.
• Better understand the general overview of
What is class diagram the schematics of an application.
• Visually express any specific needs of a
system and disseminate that information
throughout the business.
• Create detailed charts that highlight any
specific code needed to be programmed
and implemented to the described
structure.
• Provide an implementation-independent
description of types used in a system that
are later passed between its components.
Remove
Wondershare
Watermark PDFelement

UML: Unified Modeling Language


Basic components of a class diagram 3
The standard class diagram is composed of three sections:
• Upper section: Contains the name of the class. This
section is always required, whether you are talking about the
classifier or an object.
• Middle section: Contains the attributes of the class. Use
this section to describe the qualities of the class. This is only
required when describing a specific instance of a class.
• Bottom section: Includes class operations (methods).
Displayed in list format, each operation takes up its own
line. The operations describe how a class interacts with data.

Member access modifiers


All classes have different access levels depending on
the access modifier (visibility). Here are the access
levels with their corresponding symbols:
Public (+)
Private (-)
Protected (#)
Package (~)
Derived (/)
Static (underlined)
Remove
Wondershare
Watermark PDFelement

UML: Unified Modeling Language


4

The above program can be written form UML class


diagram
Remove
Wondershare
Watermark PDFelement

UML: Unified Modeling Language


Relationship Types 5 Employee
1. Generalization
2. Association
1
i. Aggregation Manager HR
ii. Composition
3. Realization Example[Generalization]: here Manager & HR are also
Employee so Manager & HR are general version of
Relationship Types Symbol Employee. Attributes in Employee are available in Manager
& HR in addition to their own attributes. It is also
referred to as inheritance

Realization
Remove
Wondershare
Watermark PDFelement

UML: Association
What is Association?
When two classes communicate or passes
information to each other . Draw a straight line
6
2
between them.
Exmaple:
Example of Association

Here Student and Course communicate to each


other like one student has several courses and one
course has several students

Other Examples of Association


Remove
Wondershare
Watermark PDFelement

UML: Unified Modeling Language


Types of Association 7

1. Aggregation 3
2. Composition
What is Aggregation?
Aggregation implies a relationship where the child
can exist independently of the parent.

Computer keyboard

Here keyboard is a part of Computer but if Computer


damage/doesn’t exits still Keyboard can exits and it
can be a part of other computer
Remove
Wondershare
Watermark PDFelement

UML: Composition
What is Composition? House Room
Composition implies a relationship where the Example: House (parent) and Room (child). Rooms
child cannot exist independent of the parent. don't exist separate to a House.

More Examples
* Person & Leg
* Whatsapp & WhGroup

Example: If Hotel doesn’t exist then Lobby and Bathroom wouldn’t be


exist
Remove
Wondershare
Watermark PDFelement

UML: Realization
What is Realization?
In UML modeling, a realization relationship is a
relationship between two model elements, in
which one model element (the client) realizes
the behavior that the other model element (the
supplier) specifies. Several clients can realize
the behavior of a single supplier.

Shape
5
realization
Circle Rectangle
Example: shape is abstract, all implementations are
to be done in child classes
Remove
Wondershare
Watermark PDFelement

UML: Unified Modeling Language


What is Association class? 10

n UML diagrams, an association class is a class that is part of an


association relationship between two other classes. You can
attach an association class to an association relationship to provide
additional information about the relationship

Here Enrollement class keeps additional information when


association between Student and Course become established
Remove
Wondershare
Watermark PDFelement

UML: Online Shopping Example


11
Remove
Wondershare
Watermark PDFelement

UML: Unified Modeling Language


Relationship between classes 12
Remove
Wondershare
Watermark PDFelement

UML: Unified Modeling Language


C++ program for Aggregation 13

//UML Aggregation class Company{


//If Company class is deleted then string cname;
//Employee class is still on Employee* emp; //Aggregation
#include <iostream> public:
#include<bits/stdc++.h> Company(string s, Employee* e){
#include<string> cname=s;
emp=e;
using namespace std; }
void getData(){
class Employee{ cout<<"Company Name: "<<cname<<endl;
string ename; cout<<"Employee Name: "<<emp->getName()<<endl;
public: }
Employee(string s){ ~Company(){
ename=s; cout<<"Company is closed"<<endl;
} }
string getName(){ };
return ename; int main(){
} Employee e("Zaman");
~Employee(){ cout<<"Name="<<e.getName()<<endl;
cout<<"Employee is closed"<<endl; {
} Company c("HP",&e);
}; c.getData();
//Company object c is closed but
//Employee object e is still on
}
Here Company is parent (whole) and Employee is
}
child (part) as inside Company a data member emp
of Employee is declared . When Company object is
destroyed then Employee object is NOT destroyed
Remove
Wondershare
Watermark PDFelement

UML: Unified Modeling Language


C++ program for Decomposition 14

//UML Decomposition class Person{


#include <iostream> string name;
#include<string> Birthday obj;
using namespace std; public:
Person(string s,int d=0,int m=0,int y=0){
class Birthday{ name=s;
int day; obj.setDate(d,m,y);
int month; cout<<"Person Constructor is called"<<endl;
int year; }
public: void Display(){
Birthday(int d=0,int m=0,int y=0){ cout<<"Name: "<<name<<endl;
day=d; obj.Display();
month=m; }
year=y; ~Person(){
cout<<"Birthday Constructor is called"<<endl; cout<<"Person destructor is called"<<endl;
} }
void setDate(int d,int m,int y){ };
day=d;
month=m; int main(){
year=y; Person p("Ali",3,10,2000);
} p.Display();
void Display(){ //Nothing declare about Birhtday class directly
cout<<"Date: //But when Person object destroyed Birthday class
"<<day<<"/"<<month<<"/"<<year<<endl; //also destroyed
} }
~Birthday(){
cout<<"Birthday destructor is called"<<endl;
}
Here Person is parent (whole) and Birthday is child
}; (part) as inside Person a data member obj of
Birthday is declared . When Person object is
destroyed then Birthday object is also is destroyed
Remove
Wondershare
Watermark PDFelement

15

THANK YOU

You might also like