0% found this document useful (0 votes)
4 views49 pages

C++ Programming Unit-2

The document outlines the concepts of Object-Oriented Design and Programming, focusing on constructors, destructors, polymorphism, and operator overloading. It details various types of constructors, including default, parameterized, and copy constructors, along with their syntax and examples. Additionally, it covers method overloading and provides insights into UML interaction diagrams, specifically sequence and collaboration diagrams.

Uploaded by

rizwanulla2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views49 pages

C++ Programming Unit-2

The document outlines the concepts of Object-Oriented Design and Programming, focusing on constructors, destructors, polymorphism, and operator overloading. It details various types of constructors, including default, parameterized, and copy constructors, along with their syntax and examples. Additionally, it covers method overloading and provides insights into UML interaction diagrams, specifically sequence and collaboration diagrams.

Uploaded by

rizwanulla2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

OBJECT ORIENTED DESIGN

AND PROGRAMMING
(CODE: 21CSC101T)
2nd Semester, B. Tech
2024-2025
UNIT-2

Dr. Bapuji Rao


Assistant Professor
Department of CSE
UNIT – 2
2
 Constructors
 Types of Constructors:
• Default Constructor,

SRM IST, DELHI-NCR CAMPUS


• Parameterized Constructor,
• Copy Constructor
 Destructor
 Polymorphism : Constructor Overloading
 Method Overloading
 Operator Overloading
 UML Interaction Diagram :
• Sequence Diagram
• Collaboration Diagram
DR . BAPUJI RAO, Department of CSE(CORE)
CONSTRUCTORS
3

 It is a special member function having the name of class itself.


 It invokes automatically at the time of object creation.
 It assigns values to the data members of the object during object creation.

SRM IST, DELHI-NCR CAMPUS


 In general, constructors are declared under public access modifiers of the class.
 It has no return value but may or may not have arguments.
 A constructor can be overloaded.
 There are three types of constructors.
• Default / Automatic Constructor
• Parameterized Constructor
• Copy Constructor

DR . BAPUJI RAO, Department of CSE(CORE)


DEFAULT / AUTOMATIC CONSTRUCTOR
4

 It has no argument.
 It invokes automatically as soon as class gets instantiated.

SRM IST, DELHI-NCR CAMPUS


 Syntax-1:  Syntax-2:
class class_name class class_name
{ {
private: private:
// data member(s); // data member(s);
public: public:
// constructor inline definition class_name( ); // constructor outline declaration
class_name( ) };
{ class_name :: class_name ( ) // constructor outline definition
// statement(s); {
} // statement(s);
}; }

DR . BAPUJI RAO, Department of CSE(CORE)


EXAMPLE
// Without constructor // Using constructor 5
class Number class Number
{ int a; {
public: int a;
void Assign( ) public:
{ // default constructor definition

SRM IST, DELHI-NCR CAMPUS


a = 20; Number( )
} {
void Show( ) OUTPUT a = 20;
{ }
cout<<"A= "<<a<<endl; A = 20 void Show( )
} A = 20 {
}; cout<<"A= "<<a<<endl;
void main( ) }
{ };
Number A, B; void main( )
A.Assign( ); {
B.Assign( ); Number A, B;
A.Show( ); A.Show( );
B.Show( ); B.Show( );
} }
DR . BAPUJI RAO, Department of CSE(CORE)
PARAMETERIZED CONSTRUCTOR
6

 It has argument(s).
 It assigns different values to the data members of objects at the time of

SRM IST, DELHI-NCR CAMPUS


declaration.
 The parameterized constructor can be invoked in TWO different ways,
i.e., implicit and explicit.
 In Implicit call, it automatically calls by matching the arguments passed
along with the object.
 In Explicit call, it calls by its name with argument(s) passed. Finally, the
anonymous object is created and assigned to the newly declared object.

DR . BAPUJI RAO, Department of CSE(CORE)


STNTAX
7

class class_name
{
private:

SRM IST, DELHI-NCR CAMPUS


// data member(s);
public:
class_name (data_type1 var1, ……) // parameterized inline constructor definition
{
// statement(s);
}
};
void main ( )
{
class_name object_name (Argument-1, Argument-2,……); // implicit call

class_name object name = class_name (Argument-1, … …); // explicit call


}

DR . BAPUJI RAO, Department of CSE(CORE)


EXAMPLE
8

class Number
{
int a; void main ( )
public: {

SRM IST, DELHI-NCR CAMPUS


// parameterized constructor declaration or prototype // Implicit call
Number(int); Number A(6);
void Show( )
OUTPUT
{ // Explicit call
cout<<"A="<<a<<endl; Number B = Number(7);
A= 6
} A= 7
};
A.Show( );
// parameterized constructor definition
Number :: Number(int b) B.Show( );
{ }
a = b;
}

DR . BAPUJI RAO, Department of CSE(CORE)


COPY CONSTRUCTOR
9

 The constructor’s argument as reference object kind then that constructor is said to be a
Copy Constructor.

SRM IST, DELHI-NCR CAMPUS


 Syntax:
class class_name
{
private:
// Data Member(s);
public:
class_name (class_name &object_name)
{
// Statement(s);
}
};

DR . BAPUJI RAO, Department of CSE(CORE)


EXAMPLE
10

#include<iostream.h>
class COPY void main ( )
{ {
int a; // implicit call to default constructor

SRM IST, DELHI-NCR CAMPUS


public: COPY A;
COPY( ) // Default constructor // implicit call to copy constructor
{ COPY B(A); OUTPUT
a = 10; // explicit call to copy constructor A = 10
} COPY C = B; A = 10
COPY(COPY &obj) // copy constructor // explicit call to copy constructor A = 10
{ COPY D = COPY(C); A = 10
a = obj.a;
A.Show ( );
}
void Show( ) B.Show ( );
{ C.Show ( );
cout<<"A="<<a<<endl; D.Show ( );
} }
}; DR . BAPUJI RAO, Department of CSE(CORE)
CONSTRUCTOR WITH DEFAULT
ARGUMENT 11

void main( )
class Number {
{ // Automatic call to Parameterized constructor
int a; // with default argument

SRM IST, DELHI-NCR CAMPUS


public: Number A;
// parameterized constructor // Implicit call
// definition with default argument Number B(6);
Number(int b=0) // Explicit call
{ Number C = Number( );
a = b; // Explicit call
} Number D= 67; OUTPUT
void Show ( ) A.Show ();
A= 0
{ B.Show ();
A= 6
cout<<"A="<<a<<endl; C.Show ();
A= 0
} D.Show ();
A = 67
}; }

DR . BAPUJI RAO, Department of CSE(CORE)


DESTRUCTOR
12
 It is also a special member function whose name is the class itself .
 Its declaration starts with the operator tilde (~).
 It invokes automatically as soon as the object leaves from the locality
where it was declared earlier.

SRM IST, DELHI-NCR CAMPUS


 A destructor has no argument and no return value.
 A destructor cannot be overloaded i.e. a class has only one destructor but
can have any number of constructors.
Syntax:
class class_name
{
// data member(s);
public:
~ class_name( )
{
// statement(s);
}
}; DR . BAPUJI RAO, Department of CSE(CORE)
EXAMPLE
13

#include<iostream.h> void main( )


int count; // global variable with initial value zero (0) {
class ARS ARS A, B, C;
{ }

SRM IST, DELHI-NCR CAMPUS


public:
ARS( )
{
count++;
cout<<"Object = "<<count<<" Invoked Constructor\n";
} OUTPUT
~ARS( ) Object = 1 Invoked Constructor
{ Object = 2 Invoked Constructor
cout<<"Object = "<<count<<" Invoked Destructor\n"; Object = 3 Invoked Constructor
count--; Object = 3 Invoked Destructor
} Object = 2 Invoked Destructor
}; Object = 1 Invoked Destructor

DR . BAPUJI RAO, Department of CSE(CORE)


POLYMORPHISM
14

SRM IST, DELHI-NCR CAMPUS


COMPILE-TIME RUN-TIME

FUNCTION OPERATOR DYNAMIC


OVERLOADING OVERLOADING BINDING

 It allows a single name / operator to be associated with different operations


depending on the type of data passed to it.

DR . BAPUJI RAO, Department of CSE(CORE)


CONSTRUCTOR OVERLOADING
15

 Declaration of constructors with different parameter list is known as Constructor Overloading.

 Syntax:

SRM IST, DELHI-NCR CAMPUS


class Class_Name
{
// Data Member(s);
public:
Class_Name( )
{
// Statement(s);
}
Class_Name( Argument(s) List Declaration)
{
// Statement(s);
}
};
DR . BAPUJI RAO, Department of CSE(CORE)
EXAMPLE
16
class Number
{ void main ()
int a; {
public: Number A; // Default constructor call
// default constructor definition Number B(6); // Implicit call

SRM IST, DELHI-NCR CAMPUS


Number ( ) Number C = Number(7); // Explicit call
{
Number D = 67; // Explicit call
a = 0;
A.Show( );
}
B.Show( );
// parameterized constructor definition
C.Show( );
Number (int b) D.Show( );
{ }
a = b;
} OUTPUT
void Show ( ) A= 0
{ A= 6
cout<<"A="<<a<<endl; A= 7
} A = 67
}; DR . BAPUJI RAO, Department of CSE(CORE)
FUNCTION OVERLOADING (STATIC BINDING)
17
 Defining functions with same name and different signatures.
(Signature means argument and return value type)

EXAMPLE:

SRM IST, DELHI-NCR CAMPUS


#include<iostream.h>
int ABS (int a)
{ void main ( )
return (abs(a)); {
} int a = -7, res1 = ABS(a);
float ABS (float b) float b = -66.77, res2 = ABS(b);
{ cout << "Absolute value of " <<a<< "="<<res1<<endl;
return (fabs (b)); cout << "Absolute value of "<<b<< "=" <<res2;
} }

OUTPUT
Absolute value of -7 = 7
Absolute value of -66.77 = 66.77
DR . BAPUJI RAO, Department of CSE(CORE)
MEMBER FUNCTION / METHOD OVERLOADING
18
 Defining member functions with same name and different
signatures in a CLASS.
EXAMPLE: #include<iostream.h> void main ( )

SRM IST, DELHI-NCR CAMPUS


#include<math.h> {
ABSOLUTE obj;
class ABSOLUTE
int a = -7, res1 = obj.ABS(a);
{
float b = -66.77, res2 = obj.ABS(b);
public:
cout << "Absolute value of " <<a<< "="<<res1<< endl;
int ABS (int a)
cout << "Absolute value of "<<b<< "=" <<res2;
{
}
return (abs(a));
}
float ABS (float b) OUTPUT
{
Absolute value of -7 = 7
return (fabs (b));
Absolute value of -66.77 = 66.77
}
};
DR . BAPUJI RAO, Department of CSE(CORE)
OPERATOR OVERLOADING
19

 Definition-1:
To use the existing operators in the member function of a class. So, that the
resulting operator is used with the objects of its class is called operator

SRM IST, DELHI-NCR CAMPUS


overloading.
 Definition-2:
The ability to provide the operators with a special meaning for a data type is
known as operator overloading.
Operator Overloading

Unary Binary

Using operator( ) Using friend operator( ) Using operator( ) Using friend operator( )
DR . BAPUJI RAO, Department of CSE(CORE)
OPERATOR OVERLOADING
20

 Operators cannot be overloaded with operator( ) member function


• Member or member access operator (.)
• Pointer to member operator (. *)

SRM IST, DELHI-NCR CAMPUS


• Scope resolution operator(::)
• Ternary operator (?:)
• sizeof( ) operator
• Pre-processor symbols (# and # #)

 Operators cannot be overloaded with friend operator( ) function


• Parentheses (( ))
• Square Brackets ([ ])
• Right Arrow Operator (→)
• Assignment Operator (=)
DR . BAPUJI RAO, Department of CSE(CORE)
UNARY OPERATOR OVERLOADING USING operator( )
MEMBER FUNCTION
21

 The operator( ) has no argument and no return value.


 Syntax:
class class_name

SRM IST, DELHI-NCR CAMPUS


{
private:
// data member(s);
public:
void operator operator_to_be_overloaded( ) // prefix
{
// statement(s);
}
void operator operator_to_be_overloaded(int) // postfix
{
// statement(s);
}
};
DR . BAPUJI RAO, Department of CSE(CORE)
EXAMPLE
22

void operator ++( ) // pre-increment


{
#include<iostream.h> ++a;
class IncDec }

SRM IST, DELHI-NCR CAMPUS


{ void operator ++(int) // post-increment
int a; {
public: a++;
void Assign (int b) }
{ void operator --( ) // pre-decrement
a = b; {
} --a;
void Show ( ) }
{ void operator --(int) // post-decrement
cout<<"A="<<a<<endl; {
} a--;
}
};
DR . BAPUJI RAO, Department of CSE(CORE)
Continue…
void main ( ) a a 23
{
obj1 obj2
IncDec obj1, obj2;
obj1.Assign(7); a a
obj2.Assign(67); obj1 7 obj2 67

SRM IST, DELHI-NCR CAMPUS


OUTPUT
obj1.Show ( );
obj2.Show ( ); A= 7
a a A = 67
++obj1;
obj2++; obj1 8 obj2 68 A=8
obj1.Show ( ); A = 68
obj2.Show ( );
A= 7
obj1--; a a A = 67
--obj2;
obj1 7 obj2 67
obj1.Show ( );
obj2.Show ( );
} DR . BAPUJI RAO, Department of CSE(CORE)
UNARY OPERATOR OVERLOADING USING friend
operator( ) FUNCTION
24

 The operator( ) has one argument of class kind and may or may not have a return value.
 The operator( ) function needs to be declared as friend in the class.

SRM IST, DELHI-NCR CAMPUS


 Syntax:
class class_name
{
private:
// data member(s);
public:
friend return_type operator operator_to_be_overloaded (class_name object_name)
{
// statement(s);
}
};

DR . BAPUJI RAO, Department of CSE(CORE)


EXAMPLE
25
#include<iostream.h> void main ( )
class Negate { a a
{ Negate obj1, obj2; obj1 obj2
int a;
a a
public: obj1.Assign (7);
obj1 7 obj2 -67

SRM IST, DELHI-NCR CAMPUS


void Assign (int b) obj2.Assign (-67);
{
a = b; obj1.Show ();
} obj2.Show ();
void Show ( ) a a
{ -obj1;
obj1 7 obj2 67
cout<<"A="<<a<<endl; -obj2;
}
friend void operator -(Negate &obj) obj1.Show ( ); OUTPUT
{ obj2.Show (); A= 7
if(obj.a<0) } A = -67
obj.a=obj.a*-1; // or obj.a =-obj.a; A= 7
} A = 67
}; DR . BAPUJI RAO, Department of CSE(CORE)
BINARY OPERATOR OVERLOADING USING operator( )
Member FUNCTION
26

 The operator( ) member function has one argument and may


or may not have a return value.

SRM IST, DELHI-NCR CAMPUS


 Syntax:
class class_name
{
private:
// data member(s);
public:
return_type operator operator_to_be_overloaded(class_name object_name)
{
// statemnt(s);
}
};

DR . BAPUJI RAO, Department of CSE(CORE)


EXAMPLE
27

Program to find Sum, Difference, Product, and Division of two numbers


using Operator Overloading.

SRM IST, DELHI-NCR CAMPUS


#include<iostream.h> OOL operator +(OOL obj) num
class OOL { obj 3
{ OOL temp; num
float num; temp.num = num + obj.num;
temp 10
public: return temp;
void Assign(int a) }
{
num = a; OOL operator -(OOL obj) num
} { obj 3
void Show( ) OOL temp;
num
{ temp.num = num - obj.num;
cout<<num<<endl; temp 4
return temp;
} }
DR . BAPUJI RAO, Department of CSE(CORE)
CONTINUE… void main ( )
{
num num
A B
OOL A, B; 28

A.Assign (7); num num


OOL operator *(OOL obj) B.Assign (3); A 7 B 3
num
{ obj 3
OOL temp; OOL C = A + B; num num

SRM IST, DELHI-NCR CAMPUS


OOL D = A - B; C 10 D 4
temp.num = num * obj.num; num
OOL E = A * B;
return temp; temp 21 OOL F = A / B; num num
} E 21 F 2.33
cout<<"Two Numbers\n";
A.Show ( );
OOL operator /(OOL obj) B.Show ( );
{ num OUTPUT
cout<<"Sum = ";
OOL temp; obj 3 C.Show ( ); Two Numbers
temp.num = num / obj.num; cout<<"Difference = "; 7
return temp; num D.Show ( ); 3
} temp 2.33 cout<<"Product = "; Sum = 10
}; E.Show ( ); Difference = 4
cout<<"Division = ";
Product = 21
F.Show ( );
}
Division = 2.33
DR . BAPUJI RAO, Department of CSE(CORE)
EXAMPLE
29

Using operator overloading add and subtract two matrices of order 2X3.

SRM IST, DELHI-NCR CAMPUS


#include<iostream.h> void Matrix::Read( ) void Matrix::Display( )
class Matrix { {
{ for (int i=0; i<2; i++) for (int i=0; i<2; i++)
float mat[2][3]; { {
public: for (int j=0; j<3; j++) for (int j=0; j<3; j++)
void Read ( ); { cout<<mat[i][j]<<" ";
void Display ( ); cout<<"Enter a Number :"; cout<<endl;
Matrix operator +(Matrix); cin>>mat[i][j]; }
Matrix operator -(Matrix); } }
}; }
}

DR . BAPUJI RAO, Department of CSE(CORE)


CONTINUE…
30

Matrix Matrix::operator +(Matrix obj) Matrix Matrix::operator -(Matrix obj)


{ {
Matrix temp; Matrix temp;

SRM IST, DELHI-NCR CAMPUS


for (int i=0; i<2; i++) for (int i=0; i<2; i++)
{ {
for (int j=0; j<3; j++) for (int j=0; j<3; j++)
{ {
temp.mat[i][j] = mat[i][j] + obj.mat[i][j]; temp.mat[i][j] = mat[i][j] - obj.mat[i][j];
} }
} }
return temp; return temp;
} }

DR . BAPUJI RAO, Department of CSE(CORE)


CONTINUE…
31

void main ( )
{
Matrix obj1, obj2;
cout<< "Enter Numbers in 1st Matrix\n";

SRM IST, DELHI-NCR CAMPUS


obj1.Read( );
cout<< "Enter Numbers in 2nd Matrix\n";
obj2.Read( );
Matrix obj3 = obj1 + obj2;
Matrix obj4 = obj1 - obj2;
cout<<"1st Matrix\n";
obj1.Display( );
cout<<"2nd Matrix\n";
obj2.Display( );
cout<<"Matrix Addition\n";
obj3.Display( );
cout<<"Matrix Subtraction\n";
obj4.Display( );
}
DR . BAPUJI RAO, Department of CSE(CORE)
BINARY OPERATOR OVERLOADING USING Friend
operator( ) FUNCTION
32

 The friend operator( ) function has two arguments.


 It may or may not have a return value.

SRM IST, DELHI-NCR CAMPUS


 It needs to be declared as friend kind in a class.

 Syntax:
class class_name
{
private:
// data member(s);
public:
friend return_type operator operator_to_be_overloaded (class_name obj1, class_name obj2)
{
// statement(s);
}
};
DR . BAPUJI RAO, Department of CSE(CORE)
EXAMPLE
33

Program to find Sum of two integers using Operator Overloading (Friend Function).
num num
#include<iostream.h> friend Number operator + (Number obj1 , Number obj2)
class Number { obj1 7 obj2 6

SRM IST, DELHI-NCR CAMPUS


{ Number T;
num
int num; T.num = obj1.num + obj2.num;
return T; T 13
public:
}
void Assign (int a)
{ friend Number operator + (Number obj , int a) num a
num = a; { obj 7 14
} Number T;
void Show ( ) T.num = obj.num + a; num
{ return T; T 21
cout<<num<<endl; }
} };

DR . BAPUJI RAO, Department of CSE(CORE)


Continue…
num num 34
void main( ) obj1 obj2
{
Number obj1, obj2; num num

obj1.Assign(7); obj1 7 obj2 6

SRM IST, DELHI-NCR CAMPUS


obj2.Assign(6);
num num

Number obj3 = obj1 + obj2; obj3 13 obj4 21

Number obj4 = obj1 + 14;

cout<<"Object1 = ";
obj1.Show ( ); OUTPUT
cout<<"Object2 = ";
Object1 = 7
obj2.Show ( );
Object2 = 6
cout<<"Object3 = ";
Object3 = 13
obj3.Show ( );
Object4 = 21
cout<<"Object4 = ";
obj4.Show ( );
} DR . BAPUJI RAO, Department of CSE(CORE)
INTERACTION DIAGRAM
35

SRM IST, DELHI-NCR CAMPUS


SEQUENCE COLLABORATION
DIAGRAM DIAGRAM

DR . BAPUJI RAO, Department of CSE(CORE)


SEQUENCE DIAGRAM
36

 Sequence Diagrams are interaction diagrams that shows how operations are
carried out.

SRM IST, DELHI-NCR CAMPUS


 It captures the interaction between objects.
 It shows the order of the interaction visually by using the vertical axis of the
diagram to represent time.
 It shows interactions or interaction Instances.
 It does not show the structural relationships between objects.

DR . BAPUJI RAO, Department of CSE(CORE)


SEQUENCE DIAGRAM
37

 A sequence diagram is made up of a collection of participants.


 A participant is the system parts that interact each other during the sequence.
 Each Class or Object in the interaction is represented by its named icon along the top of the diagram.

SRM IST, DELHI-NCR CAMPUS


 NOTATIONS IN A SEQUENCE DIAGRAM
• Frames
• Lifelines
• Messages and Focus Control
• Combined Fragments
• Interaction Occurrences
• States
• Continuations
• Textual Annotation
• Tabular Notation

DR . BAPUJI RAO, Department of CSE(CORE)


FRAMES
Lifelines and Message Flows 38

 TIME:
sd Frame_Name • The vertical axis represents time
proceedings (or progressing) down

SRM IST, DELHI-NCR CAMPUS


Time the page.
• Time in a sequence diagram is all
about ordering, not duration.

 OBJECTS:
• The horizontal axis shows the elements that are involved in the interaction.
• The objects involved in the operation are listed from left to right according to when they
take part in the message sequence.
• The elements on the horizontal axis may appear in any order.
DR . BAPUJI RAO, Department of CSE(CORE)
LIFELINES
39

:Class_Name

SRM IST, DELHI-NCR CAMPUS


 Sequence diagrams are organised according to time.
 Each participant has a corresponding lifeline.
 Each vertical dotted line is a lifeline, representing the time that an object
exists.

DR . BAPUJI RAO, Department of CSE(CORE)


MESSAGES AND FOCUS OF CONTROLS
40

:Class_Name1 :Class_Name2

SRM IST, DELHI-NCR CAMPUS


1: message
Message Start Event Execution
Occurrence
Focus of Control Start Event
(OR) 1.1: return message
Message End Event
Execution Occurrence
Execution
Occurrence End
Event
 Focus of control (Execution Occurrence):
• An execution occurrence (thin rectangle on a lifeline) represents the period
during which an element is performing an operation.
• The top and the bottom of the of the rectangle are aligned with the initiation
and the completion time respectively.
• An Event is any point in an interaction where something occurs.
DR . BAPUJI RAO, Department of CSE(CORE)
MESSAGE NOTATIONS
41

 A Message (or stimulus) is represented as an arrow going from the sender to the top of the
focus of control ( or execution occurrence) of the message on the receiver's lifeline

SRM IST, DELHI-NCR CAMPUS


SYMBOL DESCRIPTION
Synchronous: The sender waits for the message to be handled before it continues. This typically
shows a method call.
Asynchronous: The sender does not wait for the message before it continues. This allows objects
to execute concurrently.

Reply: This shows the return message from another message.

Create: This message results in the creation of a new object.


Lost: A lost message occurs whet the sender of the message is known but there is no reception of
the message.
Found: A found message indicates that although the receiver of the message is known in the
current interaction fragment, the sender of the message is unknown.

DR . BAPUJI RAO, Department of CSE(CORE)


ELEMENT CREATION & DESTRUCTION
42

 Element Creation:
• when an element is created during an interaction, the communication that

SRM IST, DELHI-NCR CAMPUS


creates the element is shown with its arrow head to the Element.

 Element Destruction:
• When an element is destroyed during an interaction, the communication that
destroys the element is shown with its arrow head to the elements lifeline
where the destruction is marked with a large symbol.

DR . BAPUJI RAO, Department of CSE(CORE)


SEQUENCE DIAGRAM OF AN
ORDER MANAGEMENT SYSTEM 43

:Customer :Order :NormalOrder

Initialization

SRM IST, DELHI-NCR CAMPUS


sendOrder( ) Confirm( )
Dispatch( )

return return

DR . BAPUJI RAO, Department of CSE(CORE)


COLLABORATION DIAGRAM
44

 A Collaboration is a collection of named objects and actors with links connecting them.
 They collaborate in performing some task.
 A Collaboration defines a set of participants and relationships that are meaningful for a given

SRM IST, DELHI-NCR CAMPUS


set of purposes.
 Objects collaborate by communicating (passing messages) with one another in order to work
together.

 NOTATIONS OF COLLABORATION DIAGRAM


• Objects
• Actors
• Links
• Messages
DR . BAPUJI RAO, Department of CSE(CORE)
COLLABORATION DIAGRAM
45

 Objects
• An object is represented by an object symbol showing the name of the object

SRM IST, DELHI-NCR CAMPUS


and its class underlined, separated by a colon(:) Object_name : class_name
• Each object in the collaboration is named and has its class specified.

 Actors
• An actor instance occurs in the collaboration diagram, as the invoker of the
interaction.
• Each Actor is named and has a role.
• One actor will be the initiator of the use case.

DR . BAPUJI RAO, Department of CSE(CORE)


COLLABORATION DIAGRAM
46

 Links
• A link is shown as a solid line between two objects.
• An object interacts with, or navigates to, other objects through its links to these

SRM IST, DELHI-NCR CAMPUS


objects.
• Message flows are attached to links and see messages.

 Messages
• A message is shown as a labelled arrow placed near a link.
• The message is directed from sender to receiver.
• The receiver must understand the message.
• The association must be navigable in that direction.
DR . BAPUJI RAO, Department of CSE(CORE)
COLLABORATION DIAGRAM OF A
HOTEL ROOM RESERVATION SYSTEM
47

window : UserInterface Object

SRM IST, DELHI-NCR CAMPUS


1: makeReservation Message

aType : HotelType Sequence Number

2: makeReservation

3: isRoom
aHotel : Hotel aReservation : Reservation aNotice : Confirmation

Self-Link OR Self-Delegation

4: isRoom DR . BAPUJI RAO, Department of CSE(CORE)


COLLABORATION DIAGRAM OF AN
ORDER MANAGEMENT SYSTEM 48

Initialization

SRM IST, DELHI-NCR CAMPUS


: Customer

1: sendOrder( )

: Order

2: confirm( )

: SpecialOrder 3: dispatch( )

End of Process
DR . BAPUJI RAO, Department of CSE(CORE)
49

SRM IST, DELHI-NCR CAMPUS


THANK YOU

DR . BAPUJI RAO, Department of CSE(CORE)

You might also like