Uploaded by Sa Ma

Lecture 1

advertisement
Object-Oriented Systems
CS60059
1
Object-Oriented Systems
CS60059
2
Object-Oriented Systems
CS60059
Dr. RAJIB
MALL
3
Object-Oriented Systems
CS60059
Dr. RAJIB
MALL
Professor
4
Object-Oriented Systems
CS60059
Dr. RAJIB
MALL
Professor
Department Of Computer Science &
Engineering
5
Object-Oriented Systems
CS60059
Dr. RAJIB
MALL
Professor
Department Of Computer Science &
Engineering
IIT Kharagpur.
6
About The Instructor

RAJIB MALL





7
About The Instructor

RAJIB MALL

B.E. , M.E., Ph.D from Indian Institute of
Science, Bangalore




8
About The Instructor

RAJIB MALL

B.E. , M.E., Ph.D from Indian Institute of
Science, Bangalore




9
About The Instructor

RAJIB MALL

B.E. , M.E., Ph.D from Indian Institute of
Science, Bangalore

Worked with Motorola (India)

Senior engineer and later as project manager


10
About The Instructor

RAJIB MALL

B.E. , M.E., Ph.D from Indian Institute of
Science, Bangalore

Worked with Motorola (India)


Senior engineer and later as project manager
Shifted to IIT, Kharagpur in 1994

Currently Professor
11
About The Instructor

RAJIB MALL

B.E. , M.E., Ph.D from Indian Institute of
Science, Bangalore

Worked with Motorola (India)


Senior engineer and later as project manager
Shifted to IIT, Kharagpur in 1994

Currently Professor
12
Motivation for Crediting this Course





13
Motivation for Crediting this Course

You have got a sophisticated gun




14
Motivation for Crediting this Course

You have got a sophisticated gun




15
Motivation for Crediting this Course

You have got a sophisticated gun

You are the proud owner of the nice gun!



16
Motivation for Crediting this Course

You have got a sophisticated gun

You are the proud owner of the nice gun!



17
Motivation for Crediting this Course

You have got a sophisticated gun

You are the proud owner of the nice gun!

Wanted to use it…


18
Motivation for Crediting this Course

You have got a sophisticated gun

You are the proud owner of the nice gun!

Wanted to use it…


19
Motivation for Crediting this Course

You have got a sophisticated gun

You are the proud owner of the nice gun!

Wanted to use it…

Opportunity came …

20
Motivation for Crediting this Course

You have got a sophisticated gun

You are the proud owner of the nice gun!

Wanted to use it…

Opportunity came …

21
Motivation for Crediting this Course

You have got a sophisticated gun

You are the proud owner of the nice gun!

Wanted to use it…

Opportunity came …

22
Motivation for Crediting this Course

You have got a sophisticated gun

You are the proud owner of the nice gun!

Wanted to use it…

Opportunity came …

23
Motivation for Crediting this Course

You have got a sophisticated gun

You are the proud owner of the nice gun!

Wanted to use it…

Opportunity came …

You claimed you make good use
of your gun!
24
Motivation for Crediting this Course

You have got a sophisticated gun

You are the proud owner of the nice gun!

Wanted to use it…

Opportunity came …

You claimed you make good use
of your gun!
25
Motivation
cont…





26
Motivation

cont…
You learnt Java, C++, …




27
Motivation
cont…

You learnt Java, C++, …

You know the syntax and semantics well.



28
Motivation
cont…

You learnt Java, C++, …

You know the syntax and semantics well.

You have written small programs that work.


29
Motivation
cont…

You learnt Java, C++, …

You know the syntax and semantics well.

You have written small programs that work.

You claimed you are an expert object-oriented
software developer!!

30
Motivation
cont…

You learnt Java, C++, …

You know the syntax and semantics well.

You have written small programs that work.


You claimed you are an expert object-oriented
software developer!!
This syndrome is not restricted to students
alone…
31
Plan of The Course






32
Plan of The Course

Basic concepts





33
Plan of The Course

Basic concepts

UML




34
Plan of The Course

Basic concepts

UML

Designing using UML



35
Plan of The Course

Basic concepts

UML

Designing using UML

Testing OO programs


36
Plan of The Course

Basic concepts

UML

Designing using UML

Testing OO programs
≈ 35%


37
Plan of The Course

Basic concepts

UML

Designing using UML

Testing OO programs

Object-oriented principles
≈ 35%

38
Plan of The Course

Basic concepts

UML

Designing using UML

Testing OO programs

Object-oriented principles
≈ 35%
≈ 5%

39
Plan of The Course

Basic concepts

UML

Designing using UML

Testing OO programs

Object-oriented principles

Patterns
≈ 35%
≈ 5%
40
Plan of The Course

Basic concepts

UML

Designing using UML

Testing OO programs

Object-oriented principles

Patterns
≈ 60%
≈ 35%
≈ 5%
41
Plan of The Course

Basic concepts

UML

Designing using UML

Testing OO programs

Object-oriented principles

Patterns
≈ 35%
?
≈ 60%
≈ 5%
42
Grading






43
Grading

Class Test 1 --- End Aug
10%





44
Grading

Class Test 1 --- End Aug

Mid Sem
10%
--- End Sep 25%




45
Grading

Class Test 1 --- End Aug

Mid Sem

Class Test 2 --- End Oct
10%
--- End Sep 25%
10%



46
Grading

Class Test 1 --- End Aug

Mid Sem

Class Test 2 --- End Oct

End Sem
10%
--- End Sep 25%
10%
--- End Nov 50%


47
Grading

Class Test 1 --- End Aug

Mid Sem

Class Test 2 --- End Oct

End Sem

10%
--- End Sep 25%
10%
--- End Nov 50%
Class attendance + Participation
-- 5%

48
Grading

Class Test 1 --- End Aug

Mid Sem

Class Test 2 --- End Oct

End Sem


--- End Sep 25%
10%
--- End Nov 50%
Class attendance + Participation
Bonus
10%
(Extra Marks)
---
-- 5%
???
49
Introduction

Object-oriented design (OOD) techniques
are now extremely popular:



50
Introduction

Object-oriented design (OOD) techniques
are now extremely popular:

Inception in early 1980’s and nearing maturity.


51
Introduction

Object-oriented design (OOD) techniques
are now extremely popular:

Inception in early 1980’s and nearing maturity.

Widespread acceptance in industry and
academics.

52
Introduction

Object-oriented design (OOD) techniques
are now extremely popular:

Inception in early 1980’s and nearing maturity.

Widespread acceptance in industry and
academics.

Unified Modelling Language (UML) became
an ISO standard (ISO/IEC 19501) in
2004.
53
Schematic Object-Oriented Solution for LIS
54
Schematic Object-Oriented Solution for LIS
referencebooks
members
issue-books
55
Schematic Object-Oriented Solution for LIS
referencebooks
members
issue-books
56
Schematic Object-Oriented Solution for LIS
referencebooks
members
issue-books
57
controller


Object-Oriented Development
A system is designed as a set of interacting
objects.
Objects are often real-world entities:





58


Object-Oriented Development
A system is designed as a set of interacting
objects.
Objects are often real-world entities:

Examples: an employee, a book etc.




59


Object-Oriented Development
A system is designed as a set of interacting
objects.
Objects are often real-world entities:

Examples: an employee, a book etc.




60


Object-Oriented Development
A system is designed as a set of interacting
objects.
Objects are often real-world entities:


Examples: an employee, a book etc.
Can also be conceptual objects :



61


Object-Oriented Development
A system is designed as a set of interacting
objects.
Objects are often real-world entities:


Examples: an employee, a book etc.
Can also be conceptual objects :



62


Object-Oriented Development
A system is designed as a set of interacting
objects.
Objects are often real-world entities:


Examples: an employee, a book etc.
Can also be conceptual objects :

Controller, manager, etc.


63


Object-Oriented Development
A system is designed as a set of interacting
objects.
Objects are often real-world entities:


Can also be conceptual objects :


Examples: an employee, a book etc.
Controller, manager, etc.
An object consists of data (attributes) and
functions (methods) that operate on data.

Encapsulation.
64


Object-Oriented Development
A system is designed as a set of interacting
objects.
Objects are often real-world entities:


Can also be conceptual objects :


Examples: an employee, a book etc.
Controller, manager, etc.
An object consists of data (attributes) and
functions (methods) that operate on data.

Encapsulation.
65
Class Diagram
66
Class

Template for object creation:




67
Class

Template for object creation:
 Instantiated
into objects



68
Class

Template for object creation:
 Instantiated
into objects



69
Class

Template for object creation:
 Instantiated
into objects



70
Class

Template for object creation:
 Instantiated
into objects



71
Class

Template for object creation:
 Instantiated
into objects



72
Class

Template for object creation:
 Instantiated
into objects



73
Class

Template for object creation:
 Instantiated


into objects
Examples: Employee, Book, etc.
Sometimes not intended to produce
instances:
 Abstract
classes
74
UML Class Representation

A class represents a set of objects having
similar attributes, operations, relationships and
behavior.
Window
size: Size
visibility: boolean
display()
hide()
75
UML Class Representation

A class represents a set of objects having
similar attributes, operations, relationships and
behavior.
Class Name
Window
size: Size
visibility: boolean
display()
hide()
76
UML Class Representation

A class represents a set of objects having
similar attributes, operations, relationships and
behavior.
Class Name
Attributes
Window
size: Size
visibility: boolean
display()
hide()
77
UML Class Representation

A class represents a set of objects having
similar attributes, operations, relationships and
behavior.
Class Name
Attributes
Operations
Window
size: Size
visibility: boolean
display()
hide()
78
UML Class Representation

A class represents a set of objects having
similar attributes, operations, relationships and
behavior.
Class Name
Attributes
Operations
Window
Can it have
any attributes
not explicitly
declared here?
size: Size
visibility: boolean
display()
hide()
79
UML Class Representation

A class represents a set of objects having
similar attributes, operations, relationships and
behavior.
Class Name
Attributes
Operations
Window
size: Size
visibility: boolean
display()
hide()
Can it have
any attributes
not explicitly
declared here?
Yes. A class
implicitly has
a few
association
attributes…
80
Alternate Representations of a Class in UML
81
Alternate Representations of a Class in UML
LibraryMember
LibraryMember
Member Name
Membership Number
Address
Phone Number
E-Mail Address
issueBook( );
findPendingBooks( );
findOverdueBooks( );
returnBook( );
Membership Admission Date
LibraryMember
findMembershipDetails( );
Membership Expiry Date
Books Issued
issueBook( );
findPendingBooks( );
findOverdueBooks( );
returnBook( );
findMembershipDetails( );
82
Alternate Representations of a Class in UML
LibraryMember
LibraryMember
Member Name
Membership Number
Address
Phone Number
E-Mail Address
issueBook( );
findPendingBooks( );
findOverdueBooks( );
returnBook( );
Membership Admission Date
LibraryMember
findMembershipDetails( );
Membership Expiry Date
Books Issued
issueBook( );
findPendingBooks( );
findOverdueBooks( );
returnBook( );
Attributes
findMembershipDetails( );
83
Alternate Representations of a Class in UML
LibraryMember
LibraryMember
Member Name
Membership Number
Address
Phone Number
E-Mail Address
issueBook( );
findPendingBooks( );
findOverdueBooks( );
returnBook( );
Membership Admission Date
findMembershipDetails( );
LibraryMember
Why?
Membership Expiry Date
Books Issued
issueBook( );
findPendingBooks( );
findOverdueBooks( );
returnBook( );
Attributes
findMembershipDetails( );
84
Alternate Representations of a Class in UML
LibraryMember
LibraryMember
Member Name
Membership Number
Address
Phone Number
E-Mail Address
issueBook( );
findPendingBooks( );
findOverdueBooks( );
returnBook( );
Membership Admission Date
findMembershipDetails( );
LibraryMember
Why?
Membership Expiry Date
Books Issued
issueBook( );
findPendingBooks( );
findOverdueBooks( );
returnBook( );
findMembershipDetails( );
Attributes
Methods
85
Class Attribute Examples
Java Syntax
Date birthday
UML Syntax
birthday:Date
Public int duration=100 +duration:int = 100
Private Student
students[0..MAX_Size]
-students[0..MAX_Size]:Student
86
Class Attribute Examples
Java Syntax
Date birthday
UML Syntax
birthday:Date
Public int duration=100 +duration:int = 100
Private Student
students[0..MAX_Size]
-students[0..MAX_Size]:Student
87
Class Attribute Examples
Java Syntax
Date birthday
UML Syntax
birthday:Date
Public int duration=100 +duration:int = 100
Private Student
students[0..MAX_Size]
-students[0..MAX_Size]:Student
88
Class Attribute Examples
Java Syntax
Date birthday
UML Syntax
birthday:Date
Public int duration=100 +duration:int = 100
Private Student
students[0..MAX_Size]
-students[0..MAX_Size]:Student
89
Visibility of Class of Members
Visibilty
Java Syntax
UML Syntax
public
public
+
protected
protected
#
?
package
private
~
private
90
Visibility of Class of Members
Visibilty
Java Syntax
UML Syntax
public
public
+
protected
protected
#
package
private
~
private
91
Methods

Window

size: Size
visibility: boolean

display()
hide()

92
Methods

Methods are the operations supported
by an object:
Window

size: Size
visibility: boolean

display()
hide()

93
Methods

Methods are the operations supported
by an object:
Window
 Means
for manipulating
the data of an object.

size: Size
visibility: boolean
display()
hide()

94
Methods

Methods are the operations supported
by an object:
Window
 Means
for manipulating
the data of an object.
 Invoked
by sending a
message (method call).
size: Size
visibility: boolean
display()
hide()

95
Methods

Methods are the operations supported
by an object:
Window
 Means
for manipulating
the data of an object.
 Invoked
by sending a
message (method call).
size: Size
visibility: boolean
display()
hide()
 Examples:
display(), calculate_salary(),
issue-book(), getMemberDetails(), etc.
96
Method Examples
Java Syntax
UML Syntax?
void move(int dx, int dy) ~move(int dx,int dy)
public int getSize()
+int getSize()
97
Method Examples
Java Syntax
UML Syntax?
void move(int dx, int dy) ~move(int dx,int dy)
public int getSize()
+int getSize()
98
Method Examples
Java Syntax
UML Syntax?
void move(int dx, int dy) ~move(int dx,int dy)
public int getSize()
+int getSize()
99
Are Methods and Messages Synonyms?




100
Are Methods and Messages Synonyms?

No



101
Are Methods and Messages Synonyms?

No

Message was the original concept in
object-orientation…


102
Are Methods and Messages Synonyms?

No

Message was the original concept in
object-orientation…

Methods are the later
simplifications…

103
Are Methods and Messages Synonyms?

No

Message was the original concept in
object-orientation…

Methods are the later
simplifications…

Sometimes used as synonyms
104
Are Methods and Operations Synonyms?




105
Are Methods and Operations Synonyms?

No



106
Are Methods and Operations Synonyms?


No
An operation can be implemented by
multiple methods.


107
Are Methods and Operations Synonyms?


No
An operation can be implemented by
multiple methods.
 Known
as polymorphism

108
Are Methods and Operations Synonyms?


No
An operation can be implemented by
multiple methods.
 Known
as polymorphism
 In
the absence of polymorphism-–the
two terms are synonyms.
109
110
What Are the Different Types of
Relationships That May Exist Among the
Classes in an OO Program?





111
What Are the Different Types of
Relationships That May Exist Among the
Classes in an OO Program?

Four types of class relationships:




112
What Are the Different Types of
Relationships That May Exist Among the
Classes in an OO Program?

Four types of class relationships:

Inheritance



113
What Are the Different Types of
Relationships That May Exist Among the
Classes in an OO Program?

Four types of class relationships:

Inheritance

Association


114
What Are the Different Types of
Relationships That May Exist Among the
Classes in an OO Program?

Four types of class relationships:

Inheritance

Association

Aggregation/Composition

115
What Are the Different Types of
Relationships That May Exist Among the
Classes in an OO Program?

Four types of class relationships:

Inheritance

Association

Aggregation/Composition

Dependency
116
Inheritance



117
Inheritance

Allows us to define a new class (derived
class) by extending an
existing class (base class).


118
Inheritance

Allows us to define a new class (derived
class) by extending an
existing class (base class).
 Represents
generalization
-specialization relationship.

119
Inheritance

Allows us to define a new class (derived
class) by extending an
existing class (base class).
 Represents
generalization
-specialization relationship.
 Allows
redefinition of the
existing methods (method
overriding).
120
Inheritance

Allows us to define a new class (derived
class) by extending an
existing class (base class).
LibraryMember
Base Class
 Represents
generalization
-specialization relationship.
 Allows
redefinition of the
existing methods (method
overriding).
Faculty
Students
Staff
Derived
Classes
UnderGrad
PostGrad
Research
121
Inheritance Example
Animal
“A Dog ISA Animal”
Dog
122
Hmmm… not really…
123
Inheritance: One More Example
Library
Member
Student
Faculty
25
124
Inheritance: One More Example
Library
Member
Student
“A Student ISA Library Member”
Faculty
25
125
Inheritance: One More Example
Library
Member
Student
“A Student ISA Library Member”
“A Faculty ISA Library Member”
Faculty
25
126
Inheritance: Semantics

Lets a subclass inherit attributes and
methods of a base class.
127
Inheritance: Semantics

Lets a subclass inherit attributes and
methods of a base class.
LibraryMember
Faculty
UnderGrad
Students
PostGrad
Base Class
Staff
Derived
Classes
Research
128
Inheritance: An Alternate Representation
LibraryMember
Faculty
UnderGrad
Students
PostGrad
Base Class
Staff
Derived
Classes
Research
129
Inheritance Example
130
Inheritance Example
Library
Book
issuable
Issuable
Single Volume
Book
Issuable
BookSet
reference
Reference
Single Volume
Book
Reference
BookSet
Discriminator: allows to group subclasses into
clusters that correspond to a semantic category.
131
Inheritance Example
Library
Book
issuable
Issuable
Single Volume
Book
Issuable
BookSet
reference
Reference
Single Volume
Book
Reference
BookSet
Discriminator: allows to group subclasses into
clusters that correspond to a semantic category.
132
Multiple Inheritance
133
Multiple Inheritance
LibraryMember Base Class
Faculty
Students
Staff
LibraryMember Base Class
Derived
Faculty
Classes
Students
Staff
Multiple
Inheritance
UnderGrad
PostGrad
Research
UnderGrad
PostGrad
Research
134
Multiple Inheritance: Can Cause Repeated
Inheritance…


May lead to inconsistency
LibraryMember Base Class
In C++ handled by using
Faculty
virtual base class
Students
Staff
Multiple
Inheritance

UnderGrad
PostGrad
Research
135
Multiple Inheritance: Can Cause Repeated
Inheritance…



May lead to inconsistency
LibraryMember Base Class
In C++ handled by using
Faculty
virtual base class
Students
Staff
Multiple
Inheritance
In Java handled by
using Interface class
UnderGrad
PostGrad
Research
136
Download