SlideShare a Scribd company logo
Principles of Object Oriented
Programming (OOP)
Presentation
On
By
Mr. Shibdas Dutta
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
2
Topics to be Covered
• Overview of OOP
• Concepts of OOP
• Principles of OOP
• Why OOP
• Relationships in OOP
• Conclusions
• Questions
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
3
Overview of OOP
 OOP has roots from 1960s when h/w & s/w became
increasingly complex, and also quality often
compromised.
 Uses “Object” which interacts with design applications
and programs.
 Focuses on “data” rather “process”.
 Programs composed of “Object” i.e. “Modules”.
 Object contains all “data” to manipulate its own data
structure unlike modular programming which focused to
“function”.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
4
Overview of OOP (Contd…)
 Collection of “co-operating” object rather “sub-routines”.
 Each object is capable of receiving messages,
processing data and sending messages to other object.
 “Object” can be viewed as an independent “machine”
with distinct role.
 For example: Smalltalk, Ruby, Simula, Algol, Python,
C++, Java to mention a few.
 Remember, Smalltalk is the first OOP.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
5
Concept Of OOP
Fundamental concepts of OOP are as follows:
 Class
 Object
 Instance & Object State
 Method
 Message Passing
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
6
Class
 Is a “blueprint” or “factory” that describes the “nature” of
“some-thing”
 “nature” – is thing’s characteristics (i.e. ‘attributes’, ‘fields’
or ‘properties’) and behaviors (i.e. ‘thing’s can do’ and
‘method/features’).
 “some-thing” – is the “Object” itself.
 For example: the class DOG would consists of
characteristics shared by all dogs, such as no. of legs,
color etc. and the ability to bark and sit are the behaviors.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
7
Object
 A pattern of a class i.e. class DOG defines all
possible dogs by listings the characteristics and
behaviors they can have.
 The object Lassie is one particular dog, with
particular versions of the characteristics.
Obj1-Lassie
Obj2-Labrador
Obj3-Breeder
Class DOG
Legs
Color
Ear
Bark()
Sit()
Walk()
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
8
Instance & Object State
 When Object is in runtime position, is called Instance.
 The Lassie object is an instance of the DOG class.
 The set of all values of the attributes of a particular object
is called its “state”.
 For example: Class.DOG (no_of_Legs,Color,Ear_type);
Obj1.Lassie (‘4’,”Yellow”,”Thin & Long”);
Obj2.Labrador (‘4’,”Green”,”Big”);
Obj3.Breeder (‘4’,”White”,”Very Small”);
Object State
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
9
Method
 An object’s ability.
 For example: Lassie, being a dog, has the ability to bark,
so bark() is one of Lassie’s method.
 Similarly, sit(), eat() and walk() are also methods of Lassie
object.
Generally, all behaviors of object should be represented
by methods() in program.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
10
Message Passing
 The process by which an object sends data to another
object or asks the other object to invoke a method.
 For example: the object called Breeder may tell the
Lassie’s object to sit by passing a “SIT Down” message
which invokes Lassie’s “Sit” method.
Sit() Sit()
“SIT Down”
Obj3. Breeder Obj1. Lassie
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
11
Principles of OOP
 There are many opinions of what it means for a
development systems or languages to be “Object
Oriented”.
 However, it is widely agree that any language that claims
to be object oriented must at least support:
Encapsulation, Data Abstraction,
Inheritance and Polymorphism.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
12
Encapsulation
 Is the hiding of data implementation by restricting access
to “accessor” and “mutator”.
 “accessor” – is a method to “access” the data/info. of
object by using get method as following program:
( I am using VB.Net since in my opinion it is easier to read and understand positively
)
Public Class Person
Private _fullName As String = "Raymond Lewallen"
Public ReadOnly Property FullName() As String
Get
Return _fullName
End Get
End Property
End Class
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
13
Encapsulation (Contd…)
 “mutator” – is a public method to “modify” the data/info. of an object
using set method as following program:
Public Class Person
Private _fullName As String = "Raymond Lewallen“
Public Property FullName() As String
Get
Return FullName
End Get
Set(ByVal value As String)
_fullName = value
End Set
End Property
End Class
This type of data protection and implementation protection without breaking
the other code that is using in rest of the program, is called Encapsulation.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
14
Data Abstraction
 It is the simplest principle to understand.
 Is the developments of classes and objects rather
implementations details.
 It denotes a “model” or “view” of item (object).
 It is used to manage complexity by decompose complex
system into smaller components.
Definition: “An abstraction denotes the essential
characteristics of an object that distinguish it from all
other kinds of object and thus provide defined conceptual
boundaries, relative to the perspective of the viewer”.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
15
Data Abstraction (Contd…)
Public Class Person
Private _height As Int
Public Property Height() As Int
Get
Return _height
End Get
Set(ByVal Value As Int)
_height = Value
End Set
End Property
Lets, look at this code for a person object
(“height”,”weight” and “age” as attributes).
 Private _weight As Int
 Public Property Weight() As Int
 Get
 Return _weight
 End Get
 Set(ByVal Value As Int)
 _weight = Value
 End Set
 End Property
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
16
Data Abstraction (Contd…)
Private _age As Int
Public Property Age() As Int
Get
Return _age
End Get
Set(ByVal Value As Int)
_age = Value
End Set
End Property
 Public Sub Sit()
 // Code that makes the person sit
 End Sub
 Public Sub Run()
 // Code that makes the person run
 End Sub
 Public Sub Cry()
 // Code that make the person cry
 End Sub
 Public Function CanRead() As Boolean
 // Code that determines if the person can read
// and returns a true or false
 End Function
 End Class
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
17
Data Abstraction (Contd…)
 So, I have create a software model of a person object.
 I have created an abstract type of what a person object is to us
outside of the software world.
 The abstract person is defined by the operations that can be
performed on it, and the information we can get from it and give to it.
 What does the abstracted person object look like to the software
world that doesn't have access to its inner workings?
 Can't really see what the code is that makes the person run!!!
So, in short, data abstraction is nothing more than the implementation of
an object that contains the same essential properties and actions, we
can find in the original object we are representing.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
18
Inheritance
 Objects can relate to each other with either a “has a”,
“uses a” or an “is a” relationship.
 “Is a” is the inheritance way of object relationship.
 For example, take a library inventory system.
 Lets, A library lends Book, Magazine, Audiocassette
and Microfilm to people.
On some level, these are treated the same due to some features
should be common but are not identical because a book has an
ISBN and a magazine does not or audiocassette has a play length
where as microfilm cannot be checked out overnight!!
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
19
Inheritance (Contd…)
 Each of these library’s loanable assets should be represented
by its own class definition named “LibraryAsset”, called a
superclass or base class.
 All assets i.e. (Book, Magazine, Audiocassette and Microfilm)
are sub classes or derived classes, so they inherit base class
characteristics.
 All assets have a title, a date of acquisition, a replacement
cost and checked out or available for checked out.
 Let us look at “LibraryAsset” Base class. This will be used as
the base class for Sub class “Book” :
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
20
Inheritance (Contd…)
LibraryAsset { }
Title
Author
Dt._Of_acquisition
Checked_Out
ISBN
Replacement_Cost
Book { } Magazine { } Audiocassette { } Microfilm { }
Zone Play_Length Film_Color
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
21
Inheritance (Contd…)
Public Class LibraryAsset
Private _title As String
Public Property Title() As String
Get
Return _title
End Get
Set(ByVal Value As String)
_title = Value
End Set
End Property
 Private _checkedOut As Boolean
 Public Property CheckedOut() As Boolean
 Get
 Return _checkedOut
 End Get
 Set(ByVal Value As Boolean)
 _checkedOut = Value
 End Set
 End Property
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
22
Inheritance (Contd…)
Private _dateOfAcquisition As DateTime
Public Property DateOfAcquisition() As DateTime
Get
Return _dateOfAcquisition
End Get
Set(ByVal Value As DateTime)
_dateOfAcquisition = Value
End Set
End Property
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
23
Inheritance (Contd…)
Private _replacementCost As Double
Public Property ReplacementCost() As Double
Get
Return _replacementCost
End Get
Set(ByVal Value As Double)
_replacementCost = Value
End Set
End Property
End Class
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
24
Inheritance (Contd…)
The inheritance relationship is called the “is a” relationship. A book
“is a” LibraryAsset, as are the other 3 assets. Lets, look at the “Book”
sub class.
Public Class Book
Inherits LibraryAsset
Private _author As String
Public Property Author() As String
Get
Return _author
End Get
Set(ByVal Value As String)
_author = Value
End Set
End Property
Private _isbn As String
Public Property Isbn() As String
Get
Return _isbn
End Get
Set(ByVal Value As String)
_isbn = Value
End Set
End Property
End Class
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
25
Inheritance (Contd…)
Now, lets create an instance of the book class so we can record a
new book into the library inventory:
Dim myBook As Book = New Book
myBook.Author = "Sahil Malik"
myBook.CheckedOut = False
myBook.DateOfAcquisition = #2/15/2005#
myBook.Isbn = "0-316-63945-8"
myBook.ReplacementCost = 59.99
myBook.Title = "The Best Ado.Net Book You'll Ever Buy"
Hence, when we create a new book, we have all the properties of
the LibraryAsset class available to us as well, because we inherited
the class.
“One of the most powerful features of inheritance is the ability to
extend components without any knowledge of the way in which a
class was implemented”.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
26
Polymorphism
 Polymorphism means one name, many forms.
 Polymorphism manifests itself by having multiple methods all with the
same name, but slighty different functionality.
 There are 2 basic types of polymorphism.
 Overloading, which is referred to as compile-time polymorphism.
 Overridding, also called run-time polymorphism.
 For method overloading, the compiler determines which method will
be executed, and this decision is made when the code gets
compiled.
 For method overrriding, which method will be used, is determined at
runtime based on the dynamic type of an object.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
27
Polymorphism (Contd…)
Let’s look at some code of LibraryAsset class as following:
// Base class for library assets
Public MustInherit Class LibraryAsset
// Default fine per day for overdue items
Private Const _finePerDay As Double = 1.25
// Due date for an item that has been checked out
Private _dueDate As DateTime
Public Property DueDate() As DateTime
Get
Return _dueDate
End Get
Set(ByVal Value As DateTime)
_dueDate = Value
End Set
End Property
28
Polymorphism (Contd…)
// Calculates the default fine amount for an overdue item
Public Overridable Function CalculateFineTotal() As Double
Dim daysOverdue As Int = CalculateDaysOverdue()
If daysOverdue > 0 Then
Return daysOverdue * _finePerDay
Else
Return 0.0
End If
End Function
// Calculates how many days overdue for an item being returned
Protected Function CalculateDaysOverdue() As Int
Return DateDiff(DateInterval.Day, _dueDate, DateTime.Now())
End Function
End Class
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
29
Polymorphism (Contd…)
// Magazine class that inherits LibraryAsset
Public NotInheritable Class Magazine Inherits LibraryAsset
// No Overriding or Overloading of any function of Base
Class in Magazine class
// So, results will come as per Base class function definition
for this Magazine class
End Class
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
30
Polymorphism (Contd…)
// Book class that inherits LibraryAsset
Public NotInheritable Class Book Inherits LibraryAsset
// This is the CalculateFineTotal() function of the base class.
// This function overrides the base class function, and any call to CalculateFineTotal
from any instantiated Book class will use this function, not the base class function.
// This type of polymorphism is called overriding.
Public Overrides Function CalculateFineTotal() As Double
Dim daysOverdue As Int = CalculateDaysOverdue()
If daysOverdue > 0 Then
Return daysOverdue * 0.75
Else
Return 0.0
End If
End Function
End Class
31
Polymorphism (Contd…)
// AudioCassette class that inherits LibraryAsset
Public NotInheritable Class AudioCassette Inherits LibraryAsset
// This is the CalculateFineTotal() function (without parameter) of the base class.
// This is the CalculateFineTotal(double) function (with parameter) of the
audiocassette class.
// This function overrides the base class function, and any call to CalculateFineTotal()
from any instantiated AudioCassette Class will use this function, not the base class
function.
// This type of polymorphism is called overloading and overriding.
Public Overloads Overrides Function CalculateFineTotal() As Double
Dim daysOverdue As Int = CalculateDaysOverdue()
If daysOverdue > 0 Then
Return daysOverdue * 0.25
Else
Return 0.0
End If
End Function
32
Polymorphism (Contd…)
// This is the CalculateFineTotal() function of the audiocassette class.
// This type of polymorphism is called overloading.
Public Overloads Function CalculateFineTotal(ByVal finePerDay As Double) As Double
Dim daysOverdue As Int = CalculateDaysOverdue()
If daysOverdue > 0 AndAlso finePerDay > 0.0 Then
Return daysOverdue * finePerDay
Else
Return 0.0
End If
End Function
End Class
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
33
Polymorphism (Contd…)
Now lets look at some code that creates all these library items and
checks them in and calculates our fines based on returning them 3 days
late:
Public Class Demo
Public Sub Go()
// Set the due date to be three days ago
Dim dueDate As DateTime = DateAdd(DateInterval.Day, -3, Now())
ReturnMagazine(dueDate)
ReturnBook(dueDate)
ReturnAudioCassette(dueDate)
End Sub
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
34
Polymorphism (Contd…)
Public Sub ReturnMagazine(ByVal dueDate As DateTime)
Dim myMagazine As Magazine = New Magazine
myMagazine.DueDate = dueDate
Dim amountDue As Double = myMagazine.CalculateFineTotal()
Console.WriteLine("Magazine: {0}", amountDue.ToString())
End Sub
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
35
Polymorphism (Contd…)
Public Sub ReturnBook(ByVal dueDate As DateTime)
Dim myBook As Book = New Book
myBook.DueDate = dueDate
Dim amountDue As Double = myBook.CalculateFineTotal()
Console.WriteLine("Book: {0}", amountDue.ToString())
End Sub
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
36
Polymorphism (Contd…)
Public Sub ReturnAudioCassette(ByVal dueDate As DateTime)
Dim myAudioCassette As AudioCassette = New AudioCassette
myAudioCassette.DueDate = dueDate
Dim amountDue As Double
amountDue = myAudioCassette.CalculateFineTotal()
Console.WriteLine("AudioCassette1: {0}", amountDue.ToString())
amountDue = myAudioCassette.CalculateFineTotal(3.0)
Console.WriteLine("AudioCassette2: {0}", amountDue.ToString())
End Sub
End Class
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
37
Polymorphism (Contd…)
The output will look like the following:
Magazine: 3.75
Book: 2.25
AudioCassette1: 0.75
AudioCassette2: 9
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
38
Why OOP
 Facilitates team development.
 Easier to reuse software components and
write reusable software.
 Easier GUI (Graphical User Interface) and
multimedia programming.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
39
Relationships in OOP
 Advantages of Object-Oriented programming language is code
reuse. This reusability is possible due to the relationship b/w the
classes.
 Object oriented programming generally support 4 types of
relationships that are: inheritance , association, composition and
aggregation.
 All these relationship is based on "is-a" relationship, "has-a"
relationship and "part-of” relationship.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
Inheritance:
Inheritance is “IS-A” type of relationship.
 “IS-A” relationship is a totally based on Inheritance, which can be
of two types Class Inheritance or Interface Inheritance.
 Inheritance is a parent-child relationship where we create a new
class by using existing class code. It is just like saying that “A is
type of B”.
 For example is “Apple is a fruit”, “Ferrari is a car”.
 “HOD is a staff member of college” and “All teachers are staff
member of college”. For this assumption we can create a
“StaffMember” parent class and inherit this parent class in “HOD”
and “Teacher” class.
40 Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
Composition:
Composition is a "part-of" relationship.
 composition means use of instance variables that are references
to other objects.
 In composition relationship both entities are interdependent of
each other for example “engine is part of car”, “heart is part of
body”.
 Let us take an example of car and engine. Engine is a part of each
car and both are dependent on each other.
41 Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
Association:
Association is a “has-a” type relationship.
 Association establish the relationship b/w two classes using
through their objects.
 Association relationship can be one to one, One to many, many to
one and many to many.
 For example suppose we have two classes then these two
classes are said to be “has-a” relationship if both of these entities
share each other’s object for some work and at the same time
they can exists without each others dependency or both have their
own life time.
 For example, Employee and Manager relationship in an
organization.
42 Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
Aggregation:
One class work as owner
 In association there is not any classes (entity) work as owner but in
aggregation one entity work as owner.
 In aggregation both entities meet for some work and then get
separated.
 Aggregation is a one way association.
 Let us take an example of “Student” and “address”. Each student
must have an address so relationship b/w Student class and
Address class will be “Has-A” type relationship but vice versa is not
true(it is not necessary that each address contain by any student).
So, Student work as owner entity.
 This will be a aggregation relationship.
43 Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
44
Conclusions
 An OOP program models a world of active objects.
 An object may have its own “memory,” which may contain
other objects.
 An object has a set of methods that can process
messages of certain types.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
45
Conclusions (Contd…)
 A method can change the object’s state, send messages
to other objects, and create new objects.
 An object belongs to a particular class, and the
functionality of each object is determined by its class.
 A programmer creates an OOP application by defining
classes.
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
46
Questions
Thanks for Patience!!!
?
Company Confidential: Data-Core Systems, Inc. | datacoresystems.com

More Related Content

Similar to OOP programming for engineering students

Drupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.comDrupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.com
JD Leonard
 
M.c.a. (sem iv)- java programming
M.c.a. (sem   iv)- java programmingM.c.a. (sem   iv)- java programming
M.c.a. (sem iv)- java programming
Praveen Chowdary
 
JAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsJAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp concepts
Rahul Malhotra
 
CSc investigatory project
CSc investigatory projectCSc investigatory project
CSc investigatory project
DIVYANSHU KUMAR
 
Oop concepts classes_objects
Oop concepts classes_objectsOop concepts classes_objects
Oop concepts classes_objects
William Olivier
 
Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
BilalHussainShah5
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
Sudip Simkhada
 
Introduction to OOP.pptx
Introduction to OOP.pptxIntroduction to OOP.pptx
Introduction to OOP.pptx
ParthaSarathiBehera9
 
An Introduction to Working With the Activity Stream
An Introduction to Working With the Activity StreamAn Introduction to Working With the Activity Stream
An Introduction to Working With the Activity Stream
Mikkel Flindt Heisterberg
 
Ooad notes
Ooad notesOoad notes
Ooad notes
NancyJP
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
NuurAxmed2
 
Mikkel Heisterberg - An introduction to developing for the Activity Stream
Mikkel Heisterberg - An introduction to developing for the Activity StreamMikkel Heisterberg - An introduction to developing for the Activity Stream
Mikkel Heisterberg - An introduction to developing for the Activity Stream
LetsConnect
 
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Karen Thompson
 
C++
C++C++
C++
Rome468
 
OOP-Advanced Programming with c++
OOP-Advanced Programming with c++OOP-Advanced Programming with c++
OOP-Advanced Programming with c++
Mohamed Essam
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
Rome468
 
Object oriented software engineering concepts
Object oriented software engineering conceptsObject oriented software engineering concepts
Object oriented software engineering conceptsKomal Singh
 

Similar to OOP programming for engineering students (20)

Drupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.comDrupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.com
 
M.c.a. (sem iv)- java programming
M.c.a. (sem   iv)- java programmingM.c.a. (sem   iv)- java programming
M.c.a. (sem iv)- java programming
 
JAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsJAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp concepts
 
CSc investigatory project
CSc investigatory projectCSc investigatory project
CSc investigatory project
 
Oop concepts classes_objects
Oop concepts classes_objectsOop concepts classes_objects
Oop concepts classes_objects
 
My c++
My c++My c++
My c++
 
Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
Bp301
Bp301Bp301
Bp301
 
Introduction to OOP.pptx
Introduction to OOP.pptxIntroduction to OOP.pptx
Introduction to OOP.pptx
 
An Introduction to Working With the Activity Stream
An Introduction to Working With the Activity StreamAn Introduction to Working With the Activity Stream
An Introduction to Working With the Activity Stream
 
Mca 504 dotnet_unit3
Mca 504 dotnet_unit3Mca 504 dotnet_unit3
Mca 504 dotnet_unit3
 
Ooad notes
Ooad notesOoad notes
Ooad notes
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
 
Mikkel Heisterberg - An introduction to developing for the Activity Stream
Mikkel Heisterberg - An introduction to developing for the Activity StreamMikkel Heisterberg - An introduction to developing for the Activity Stream
Mikkel Heisterberg - An introduction to developing for the Activity Stream
 
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
 
C++
C++C++
C++
 
OOP-Advanced Programming with c++
OOP-Advanced Programming with c++OOP-Advanced Programming with c++
OOP-Advanced Programming with c++
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
 
Object oriented software engineering concepts
Object oriented software engineering conceptsObject oriented software engineering concepts
Object oriented software engineering concepts
 

Recently uploaded

AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 

Recently uploaded (20)

AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 

OOP programming for engineering students

  • 1. Principles of Object Oriented Programming (OOP) Presentation On By Mr. Shibdas Dutta Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 2. 2 Topics to be Covered • Overview of OOP • Concepts of OOP • Principles of OOP • Why OOP • Relationships in OOP • Conclusions • Questions Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 3. 3 Overview of OOP  OOP has roots from 1960s when h/w & s/w became increasingly complex, and also quality often compromised.  Uses “Object” which interacts with design applications and programs.  Focuses on “data” rather “process”.  Programs composed of “Object” i.e. “Modules”.  Object contains all “data” to manipulate its own data structure unlike modular programming which focused to “function”. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 4. 4 Overview of OOP (Contd…)  Collection of “co-operating” object rather “sub-routines”.  Each object is capable of receiving messages, processing data and sending messages to other object.  “Object” can be viewed as an independent “machine” with distinct role.  For example: Smalltalk, Ruby, Simula, Algol, Python, C++, Java to mention a few.  Remember, Smalltalk is the first OOP. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 5. 5 Concept Of OOP Fundamental concepts of OOP are as follows:  Class  Object  Instance & Object State  Method  Message Passing Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 6. 6 Class  Is a “blueprint” or “factory” that describes the “nature” of “some-thing”  “nature” – is thing’s characteristics (i.e. ‘attributes’, ‘fields’ or ‘properties’) and behaviors (i.e. ‘thing’s can do’ and ‘method/features’).  “some-thing” – is the “Object” itself.  For example: the class DOG would consists of characteristics shared by all dogs, such as no. of legs, color etc. and the ability to bark and sit are the behaviors. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 7. 7 Object  A pattern of a class i.e. class DOG defines all possible dogs by listings the characteristics and behaviors they can have.  The object Lassie is one particular dog, with particular versions of the characteristics. Obj1-Lassie Obj2-Labrador Obj3-Breeder Class DOG Legs Color Ear Bark() Sit() Walk() Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 8. 8 Instance & Object State  When Object is in runtime position, is called Instance.  The Lassie object is an instance of the DOG class.  The set of all values of the attributes of a particular object is called its “state”.  For example: Class.DOG (no_of_Legs,Color,Ear_type); Obj1.Lassie (‘4’,”Yellow”,”Thin & Long”); Obj2.Labrador (‘4’,”Green”,”Big”); Obj3.Breeder (‘4’,”White”,”Very Small”); Object State Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 9. 9 Method  An object’s ability.  For example: Lassie, being a dog, has the ability to bark, so bark() is one of Lassie’s method.  Similarly, sit(), eat() and walk() are also methods of Lassie object. Generally, all behaviors of object should be represented by methods() in program. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 10. 10 Message Passing  The process by which an object sends data to another object or asks the other object to invoke a method.  For example: the object called Breeder may tell the Lassie’s object to sit by passing a “SIT Down” message which invokes Lassie’s “Sit” method. Sit() Sit() “SIT Down” Obj3. Breeder Obj1. Lassie Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 11. 11 Principles of OOP  There are many opinions of what it means for a development systems or languages to be “Object Oriented”.  However, it is widely agree that any language that claims to be object oriented must at least support: Encapsulation, Data Abstraction, Inheritance and Polymorphism. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 12. 12 Encapsulation  Is the hiding of data implementation by restricting access to “accessor” and “mutator”.  “accessor” – is a method to “access” the data/info. of object by using get method as following program: ( I am using VB.Net since in my opinion it is easier to read and understand positively ) Public Class Person Private _fullName As String = "Raymond Lewallen" Public ReadOnly Property FullName() As String Get Return _fullName End Get End Property End Class Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 13. 13 Encapsulation (Contd…)  “mutator” – is a public method to “modify” the data/info. of an object using set method as following program: Public Class Person Private _fullName As String = "Raymond Lewallen“ Public Property FullName() As String Get Return FullName End Get Set(ByVal value As String) _fullName = value End Set End Property End Class This type of data protection and implementation protection without breaking the other code that is using in rest of the program, is called Encapsulation. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 14. 14 Data Abstraction  It is the simplest principle to understand.  Is the developments of classes and objects rather implementations details.  It denotes a “model” or “view” of item (object).  It is used to manage complexity by decompose complex system into smaller components. Definition: “An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of object and thus provide defined conceptual boundaries, relative to the perspective of the viewer”. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 15. 15 Data Abstraction (Contd…) Public Class Person Private _height As Int Public Property Height() As Int Get Return _height End Get Set(ByVal Value As Int) _height = Value End Set End Property Lets, look at this code for a person object (“height”,”weight” and “age” as attributes).  Private _weight As Int  Public Property Weight() As Int  Get  Return _weight  End Get  Set(ByVal Value As Int)  _weight = Value  End Set  End Property Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 16. 16 Data Abstraction (Contd…) Private _age As Int Public Property Age() As Int Get Return _age End Get Set(ByVal Value As Int) _age = Value End Set End Property  Public Sub Sit()  // Code that makes the person sit  End Sub  Public Sub Run()  // Code that makes the person run  End Sub  Public Sub Cry()  // Code that make the person cry  End Sub  Public Function CanRead() As Boolean  // Code that determines if the person can read // and returns a true or false  End Function  End Class Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 17. 17 Data Abstraction (Contd…)  So, I have create a software model of a person object.  I have created an abstract type of what a person object is to us outside of the software world.  The abstract person is defined by the operations that can be performed on it, and the information we can get from it and give to it.  What does the abstracted person object look like to the software world that doesn't have access to its inner workings?  Can't really see what the code is that makes the person run!!! So, in short, data abstraction is nothing more than the implementation of an object that contains the same essential properties and actions, we can find in the original object we are representing. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 18. 18 Inheritance  Objects can relate to each other with either a “has a”, “uses a” or an “is a” relationship.  “Is a” is the inheritance way of object relationship.  For example, take a library inventory system.  Lets, A library lends Book, Magazine, Audiocassette and Microfilm to people. On some level, these are treated the same due to some features should be common but are not identical because a book has an ISBN and a magazine does not or audiocassette has a play length where as microfilm cannot be checked out overnight!! Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 19. 19 Inheritance (Contd…)  Each of these library’s loanable assets should be represented by its own class definition named “LibraryAsset”, called a superclass or base class.  All assets i.e. (Book, Magazine, Audiocassette and Microfilm) are sub classes or derived classes, so they inherit base class characteristics.  All assets have a title, a date of acquisition, a replacement cost and checked out or available for checked out.  Let us look at “LibraryAsset” Base class. This will be used as the base class for Sub class “Book” : Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 20. 20 Inheritance (Contd…) LibraryAsset { } Title Author Dt._Of_acquisition Checked_Out ISBN Replacement_Cost Book { } Magazine { } Audiocassette { } Microfilm { } Zone Play_Length Film_Color Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 21. 21 Inheritance (Contd…) Public Class LibraryAsset Private _title As String Public Property Title() As String Get Return _title End Get Set(ByVal Value As String) _title = Value End Set End Property  Private _checkedOut As Boolean  Public Property CheckedOut() As Boolean  Get  Return _checkedOut  End Get  Set(ByVal Value As Boolean)  _checkedOut = Value  End Set  End Property Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 22. 22 Inheritance (Contd…) Private _dateOfAcquisition As DateTime Public Property DateOfAcquisition() As DateTime Get Return _dateOfAcquisition End Get Set(ByVal Value As DateTime) _dateOfAcquisition = Value End Set End Property Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 23. 23 Inheritance (Contd…) Private _replacementCost As Double Public Property ReplacementCost() As Double Get Return _replacementCost End Get Set(ByVal Value As Double) _replacementCost = Value End Set End Property End Class Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 24. 24 Inheritance (Contd…) The inheritance relationship is called the “is a” relationship. A book “is a” LibraryAsset, as are the other 3 assets. Lets, look at the “Book” sub class. Public Class Book Inherits LibraryAsset Private _author As String Public Property Author() As String Get Return _author End Get Set(ByVal Value As String) _author = Value End Set End Property Private _isbn As String Public Property Isbn() As String Get Return _isbn End Get Set(ByVal Value As String) _isbn = Value End Set End Property End Class Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 25. 25 Inheritance (Contd…) Now, lets create an instance of the book class so we can record a new book into the library inventory: Dim myBook As Book = New Book myBook.Author = "Sahil Malik" myBook.CheckedOut = False myBook.DateOfAcquisition = #2/15/2005# myBook.Isbn = "0-316-63945-8" myBook.ReplacementCost = 59.99 myBook.Title = "The Best Ado.Net Book You'll Ever Buy" Hence, when we create a new book, we have all the properties of the LibraryAsset class available to us as well, because we inherited the class. “One of the most powerful features of inheritance is the ability to extend components without any knowledge of the way in which a class was implemented”. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 26. 26 Polymorphism  Polymorphism means one name, many forms.  Polymorphism manifests itself by having multiple methods all with the same name, but slighty different functionality.  There are 2 basic types of polymorphism.  Overloading, which is referred to as compile-time polymorphism.  Overridding, also called run-time polymorphism.  For method overloading, the compiler determines which method will be executed, and this decision is made when the code gets compiled.  For method overrriding, which method will be used, is determined at runtime based on the dynamic type of an object. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 27. 27 Polymorphism (Contd…) Let’s look at some code of LibraryAsset class as following: // Base class for library assets Public MustInherit Class LibraryAsset // Default fine per day for overdue items Private Const _finePerDay As Double = 1.25 // Due date for an item that has been checked out Private _dueDate As DateTime Public Property DueDate() As DateTime Get Return _dueDate End Get Set(ByVal Value As DateTime) _dueDate = Value End Set End Property
  • 28. 28 Polymorphism (Contd…) // Calculates the default fine amount for an overdue item Public Overridable Function CalculateFineTotal() As Double Dim daysOverdue As Int = CalculateDaysOverdue() If daysOverdue > 0 Then Return daysOverdue * _finePerDay Else Return 0.0 End If End Function // Calculates how many days overdue for an item being returned Protected Function CalculateDaysOverdue() As Int Return DateDiff(DateInterval.Day, _dueDate, DateTime.Now()) End Function End Class Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 29. 29 Polymorphism (Contd…) // Magazine class that inherits LibraryAsset Public NotInheritable Class Magazine Inherits LibraryAsset // No Overriding or Overloading of any function of Base Class in Magazine class // So, results will come as per Base class function definition for this Magazine class End Class Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 30. 30 Polymorphism (Contd…) // Book class that inherits LibraryAsset Public NotInheritable Class Book Inherits LibraryAsset // This is the CalculateFineTotal() function of the base class. // This function overrides the base class function, and any call to CalculateFineTotal from any instantiated Book class will use this function, not the base class function. // This type of polymorphism is called overriding. Public Overrides Function CalculateFineTotal() As Double Dim daysOverdue As Int = CalculateDaysOverdue() If daysOverdue > 0 Then Return daysOverdue * 0.75 Else Return 0.0 End If End Function End Class
  • 31. 31 Polymorphism (Contd…) // AudioCassette class that inherits LibraryAsset Public NotInheritable Class AudioCassette Inherits LibraryAsset // This is the CalculateFineTotal() function (without parameter) of the base class. // This is the CalculateFineTotal(double) function (with parameter) of the audiocassette class. // This function overrides the base class function, and any call to CalculateFineTotal() from any instantiated AudioCassette Class will use this function, not the base class function. // This type of polymorphism is called overloading and overriding. Public Overloads Overrides Function CalculateFineTotal() As Double Dim daysOverdue As Int = CalculateDaysOverdue() If daysOverdue > 0 Then Return daysOverdue * 0.25 Else Return 0.0 End If End Function
  • 32. 32 Polymorphism (Contd…) // This is the CalculateFineTotal() function of the audiocassette class. // This type of polymorphism is called overloading. Public Overloads Function CalculateFineTotal(ByVal finePerDay As Double) As Double Dim daysOverdue As Int = CalculateDaysOverdue() If daysOverdue > 0 AndAlso finePerDay > 0.0 Then Return daysOverdue * finePerDay Else Return 0.0 End If End Function End Class Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 33. 33 Polymorphism (Contd…) Now lets look at some code that creates all these library items and checks them in and calculates our fines based on returning them 3 days late: Public Class Demo Public Sub Go() // Set the due date to be three days ago Dim dueDate As DateTime = DateAdd(DateInterval.Day, -3, Now()) ReturnMagazine(dueDate) ReturnBook(dueDate) ReturnAudioCassette(dueDate) End Sub Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 34. 34 Polymorphism (Contd…) Public Sub ReturnMagazine(ByVal dueDate As DateTime) Dim myMagazine As Magazine = New Magazine myMagazine.DueDate = dueDate Dim amountDue As Double = myMagazine.CalculateFineTotal() Console.WriteLine("Magazine: {0}", amountDue.ToString()) End Sub Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 35. 35 Polymorphism (Contd…) Public Sub ReturnBook(ByVal dueDate As DateTime) Dim myBook As Book = New Book myBook.DueDate = dueDate Dim amountDue As Double = myBook.CalculateFineTotal() Console.WriteLine("Book: {0}", amountDue.ToString()) End Sub Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 36. 36 Polymorphism (Contd…) Public Sub ReturnAudioCassette(ByVal dueDate As DateTime) Dim myAudioCassette As AudioCassette = New AudioCassette myAudioCassette.DueDate = dueDate Dim amountDue As Double amountDue = myAudioCassette.CalculateFineTotal() Console.WriteLine("AudioCassette1: {0}", amountDue.ToString()) amountDue = myAudioCassette.CalculateFineTotal(3.0) Console.WriteLine("AudioCassette2: {0}", amountDue.ToString()) End Sub End Class Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 37. 37 Polymorphism (Contd…) The output will look like the following: Magazine: 3.75 Book: 2.25 AudioCassette1: 0.75 AudioCassette2: 9 Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 38. 38 Why OOP  Facilitates team development.  Easier to reuse software components and write reusable software.  Easier GUI (Graphical User Interface) and multimedia programming. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 39. 39 Relationships in OOP  Advantages of Object-Oriented programming language is code reuse. This reusability is possible due to the relationship b/w the classes.  Object oriented programming generally support 4 types of relationships that are: inheritance , association, composition and aggregation.  All these relationship is based on "is-a" relationship, "has-a" relationship and "part-of” relationship. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 40. Inheritance: Inheritance is “IS-A” type of relationship.  “IS-A” relationship is a totally based on Inheritance, which can be of two types Class Inheritance or Interface Inheritance.  Inheritance is a parent-child relationship where we create a new class by using existing class code. It is just like saying that “A is type of B”.  For example is “Apple is a fruit”, “Ferrari is a car”.  “HOD is a staff member of college” and “All teachers are staff member of college”. For this assumption we can create a “StaffMember” parent class and inherit this parent class in “HOD” and “Teacher” class. 40 Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 41. Composition: Composition is a "part-of" relationship.  composition means use of instance variables that are references to other objects.  In composition relationship both entities are interdependent of each other for example “engine is part of car”, “heart is part of body”.  Let us take an example of car and engine. Engine is a part of each car and both are dependent on each other. 41 Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 42. Association: Association is a “has-a” type relationship.  Association establish the relationship b/w two classes using through their objects.  Association relationship can be one to one, One to many, many to one and many to many.  For example suppose we have two classes then these two classes are said to be “has-a” relationship if both of these entities share each other’s object for some work and at the same time they can exists without each others dependency or both have their own life time.  For example, Employee and Manager relationship in an organization. 42 Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 43. Aggregation: One class work as owner  In association there is not any classes (entity) work as owner but in aggregation one entity work as owner.  In aggregation both entities meet for some work and then get separated.  Aggregation is a one way association.  Let us take an example of “Student” and “address”. Each student must have an address so relationship b/w Student class and Address class will be “Has-A” type relationship but vice versa is not true(it is not necessary that each address contain by any student). So, Student work as owner entity.  This will be a aggregation relationship. 43 Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 44. 44 Conclusions  An OOP program models a world of active objects.  An object may have its own “memory,” which may contain other objects.  An object has a set of methods that can process messages of certain types. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 45. 45 Conclusions (Contd…)  A method can change the object’s state, send messages to other objects, and create new objects.  An object belongs to a particular class, and the functionality of each object is determined by its class.  A programmer creates an OOP application by defining classes. Company Confidential: Data-Core Systems, Inc. | datacoresystems.com
  • 46. 46 Questions Thanks for Patience!!! ? Company Confidential: Data-Core Systems, Inc. | datacoresystems.com