SlideShare a Scribd company logo
9
Features of OOP
1.Classes
2.Objects
3.Methods
4.Message passing
5.Inheritance
6.Polymorphism
7.Containership
8.Reusability
9.Delegation
10.Data abstraction and encapsulation.
Most read
14
Method and message passing
lA method is a function associated with
a class.
lIt defines the operation that the object
can execute when it receives a
message.
lOnly methods of the class can access
and manipulate the data stored in an
instance of the class.
lTwo objects can communicate with
each other through messages.
lAn object asks another object to
invoke one of its methods by sending it
a message.
Sender
object
Receiver
object
Most read
16
Polymorphism
lRefers to having several different forms.
lIt is related to methods.
lIn Python, polymorphism exists when a number of subclasses is defined which have
methods of same name.
lA function can use objects of any of the polymorphic classes irrespective of the fact that
these classes are individually distinct.
lPolymorphism can also be applied to operators.
le.g. a+b will give result of adding a and b.
lWhen we overload the +operator to be used with strings, then result is concatenation of
two strings.
Most read
UNIT-V
Object Oriented Programming
Subject :PPS
Subject Teacher :Ms. Mhaske N.R.
Programming Paradigm
lA fundamental style of programming that defines how the structure and basic
elements of a computer program will be built.
lStyle of writing programs and set of capabilities and limitations of a PL has
depends on programming paradigm it supports.
lPP can be classified as follows:
1. Monolithic Programming
2. Procedural Programming
3. Structured Programming
4. Object Oriented Programming
lEach of these paradigms has its own strengths and weaknesses
lNo single paradigm can suit all applications.
le.g. for designing computation intensive problems, procedure oriented
programming is preferred.
Monolithic Programming
lPrograms written using monolithic
programming languages such as assembly
language and BASIC consists of global data
and sequential code.
lGlobal data can be accessed and modified
from any part of program.
lSequential code is one in which all instructions
are executed in the specified sequence.
lMonolithic programs have just one program
module.
lAll the actions required to complete a task are
embedded within same application itself.
lThis makes the size of the program large and
also makes it difficult to debug and maintain.
lUsed only for small and simple applications
MOV AX, A
ADD AX, B
MOV SUM, AX
JMP STOP
……….
STOP : EXIT
ADB 10
BDB 20
SUM DB?
Global
data
Sequential
code with
jmp
instruction
Procedural Programming
lIn procedure language, a program is divided into n
number of subroutines that access global data.
lTo avoid repetition of code, each subroutine performs
a well defined task.
lA subroutine that needs the service provided by
another subroutine can call that subroutine.
lAdvantages:
l1. goal is to write correct program
l2. easier to write as compared to monolithic
lDisadvantages:
l1. writing program is complex
l2. No concept of reusability
l3. require more time and effort
l4. difficult to maintain
l5. global data may get altered.
Global data
Program
Subprogram
Structure of procedural program
Structured Programming
lAlso referred as modular programming.
lSuggested by mathematician Corrado Bohm
and Guiseppe Jacopini.
lSpecifically designed to enforce a logical
structure on the program to make it more
efficient and easier to understand and modify.
lTop-down approach
lOverall program structure is broken down into
separate modules.
lThis allows the code to be loaded into memory
more efficiently and also reused in other
programs.
lModules are coded separately and once
module is written and tested , it is then
integrated with other modules to form overall
program.
Global data
Program
Modules
Structured Program
Object Oriented Programming
lIt treats data as a critical element in program
development and restricts its flow freely
around the system.
lTask based and data based
lAll the data and tasks are grouped together in
entities known as objects.
lIt uses routines provided in the object.
lEvery object contains some data and the
operations, methods or functions that operate
on that data.
lIn this approach, the list is considered an
object consisting of the list, along with a
collection of routines for manipulating the list.
Object1
Object 2
Object 3
Object 4
Objects of a Program interact by
sending messages to each other
Object Oriented Programming
lPrograms are data centered.
lPrograms are divided into objects.
lFunctions that operate on data are tied
together with the data.
lData is hidden and not accessible by
external functions.
lNew data and functions can be easily added
as and when required.
lFollows a bottom-up approach.
Methods/functions
Private data
Object
PROCEDURAL ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING
In procedural programming, program is
divided into small parts called functions.
In object oriented programming, program
is divided into small parts called objects.
Procedural programming follows top down
approach.
Object oriented programming follows
bottom up approach.
There is no access specifier in procedural
programming.
Object oriented programming have access
specifiers like private, public, protected
etc.
Adding new data and function is not easy. Adding new data and function is easy.
Procedural programming does not have any
proper way for hiding data so it is less
secure.
Object oriented programming provides
data hiding so it is more secure.
In procedural programming, overloading is
not possible.
Overloading is possible in object oriented
programming.
In procedural programming, function is
more important than data.
In object oriented programming, data is
more important than function.
Procedural programming is based on unreal
world.
Object oriented programming is based on
real world.
Examples: C, FORTRAN, Pascal, Basic etc. Examples: C++, Java, Python, C# etc.
Features of OOP
1.Classes
2.Objects
3.Methods
4.Message passing
5.Inheritance
6.Polymorphism
7.Containership
8.Reusability
9.Delegation
10.Data abstraction and encapsulation.
Classes
lA class is used to describe something in
the world, such as occurrences, things,
external entities, etc.
lA class provides a template or blueprint
that describes the structure and behavior
of a set of similar objects.
le.g.
lConsider class student with function
showdata() and attributes namely, rollno,
name, and course.
lOnce a class is declared, programmer can
create any number of objects of that class.
lClass defines properties and behavior of
objects.
lA class is a collection of objects
lIt is a user defined datatype that behaves
same as the built in datatypes.
class student:
def __init__(self, rollno, name,course):
self.rollno=rollno
self.name=name
self.course=course
def showdata(self):
print(“Rollno=“, self.rollno)
print(“Name=“, self.name)
print(“Course=“, self.course)
Objects
lObject is an instance of a class.
lEvery object contains some data and
functions.
lThese methods store data in variables
and respond to the messages that they
receive from other objects by
executing their methods.
lWhile a class is a logical structure, an
object is a physical actuality.
lTo create object:
Obj_nmae=class_name()
To create an object of class student,
Stud=student()
Object name
Attribute 1
Attribute 2
………..
Attribute n
Function 1
Function 2
…………
Function n
Representation of an object
Class method and self argument
Exactly same as ordinary function but with one difference
Class methods must have the first argument named as self.
You do not pass a value for this parameter when you call the method.
Python provides its value automatically.
The self argument refers to the object itself.
That is, the object that has called the method.
even if a method that takes no arguments, it should be defined to accept the self.
Since the class methods uses self, they require an object or instance of the class to be
used.
For this reason, they are often referred to as instance methods.
The __init__ method(the class constructor)
The __init__ method has a special significance in Python classes.
It is automatically executed when an object of a class is created.
The method is useful to initialize the variables of the class object.
__init__ is prefixed as well as suffixed by double underscores.
e.g.
class ABC()
 def __init__(self, val)
 print(“in class method…….”)
 self.val=val
 print(“the value=”, val)
obj=ABC(10)
OUTPUT:
in class method…….
The value=10
In the __init__ method we define a variable as self.val which has exactly the same name as
that specified in the argument list.
Though the two variables have the same name, they are entirely different variables.
The self.val belongs to the newly created object.
__init__ method is automatically involved when the object of the class is created.
Method and message passing
lA method is a function associated with
a class.
lIt defines the operation that the object
can execute when it receives a
message.
lOnly methods of the class can access
and manipulate the data stored in an
instance of the class.
lTwo objects can communicate with
each other through messages.
lAn object asks another object to
invoke one of its methods by sending it
a message.
Sender
object
Receiver
object
Inheritance
lA new classis created from an existing class
lNew class known as subclass, contains the
attributes and methods of the parent class.
lThe new class known as derived class in herits
the attributes and behavior of the preexisting
class which is referred as superclass or parent
class
lTherefore inheritance relation relation is also
called as ‘is-a’ relation.
lAdvantage : ability to reuse the code
e.g. class student has data members rollno,
name, course and methods getdata(), setdata().
We can inherit two classes from student class,
namely UG and PG students.
These two classes will have all the properties
and methods of class students and in addition to
that will have even more members.
Parent
features
Parent +
child
features
Parent, base or super class
Child, derived or subclass
Polymorphism
lRefers to having several different forms.
lIt is related to methods.
lIn Python, polymorphism exists when a number of subclasses is defined which have
methods of same name.
lA function can use objects of any of the polymorphic classes irrespective of the fact that
these classes are individually distinct.
lPolymorphism can also be applied to operators.
le.g. a+b will give result of adding a and b.
lWhen we overload the +operator to be used with strings, then result is concatenation of
two strings.
Containership
lIs the ability of a class to contain objects of one of more classes as member data.
le. g. Class One an have object of class Two as its data member.
lThis would allow the object of class One to call the public functions of class Two.
lHere Class One becomes the container, whereas class Two becomes the contained
class.
lContainership is also called composition because class Oneiscomposed of class Two.
lIt represents ‘has-a’ relationship.
Reusability
lMeans developing codes that can be reused either in same program or in different
programs.
lReusability is attained through inheritance, containership and polymorphism.
encapsulation
lEncapsulation defines three access levels:
1.Public: any data or function can be accessed by any function belonging to any class.
This is the lowest level of data protection.
2. Protected: any data or function can be accessed only by that class or by any class
that is inherited from it.
3. Private: any data or function can be accessed only by that class in which it is declared.
This is the highest level of data protection.
Delegation
lIn delegation more than one object is involved in handling request.
lThe object that receives the request for a service, delegate it to another object called its
delegate.
lDelegation is based on the property that a complex object is made of several simpler
objects.
le. g. our body is made up of brain, heart, hand, eyes etc. the functioning of the whole
body as a system rests on correct functioning of the parts it is composed of.
lIn delegation, they have ‘has-a’ relationship.
Data abstraction and encapsulation
lRefer to the process by which data and functions are defined in such a way that only
essential details are revealed and the implementation details are hidden.
lThe main focus of data abstraction is to separate the interface and the implementation of
a program.
le.g. as user of television set, we can switch it on or off, change the channel, set the
volume without knowing the details about how its functionality has been implemented.
lClasses provide public methods to the outside world to provide the functionality of the
object or to manipulate the objects data.
lData encapsulation also called data hiding.
lData hiding is the technique of packing data and functions into a single component to
hide implementation details of a class from the users.
lTherefore encapsulation prevents data access by any function that is not specified in the
class.
lThis ensures integrity of the data contained in the object.

More Related Content

What's hot (20)

File handling in Python
File handling in PythonFile handling in Python
File handling in Python
BMS Institute of Technology and Management
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
P M Patil
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Abhilash Nair
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
Simplilearn
 
Class, object and inheritance in python
Class, object and inheritance in pythonClass, object and inheritance in python
Class, object and inheritance in python
Santosh Verma
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...
Edureka!
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
Emertxe Information Technologies Pvt Ltd
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer farooq
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
Megha V
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
Ravi_Kant_Sahu
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Sunil OS
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
BG Java EE Course
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
P M Patil
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
Simplilearn
 
Class, object and inheritance in python
Class, object and inheritance in pythonClass, object and inheritance in python
Class, object and inheritance in python
Santosh Verma
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...Python File Handling | File Operations in Python | Learn python programming |...
Python File Handling | File Operations in Python | Learn python programming |...
Edureka!
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer farooq
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
Megha V
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Sunil OS
 

Similar to Object oriented programming in python (20)

Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
AtharvaPimple1
 
POP vs OOP Introduction
POP vs OOP IntroductionPOP vs OOP Introduction
POP vs OOP Introduction
Hashni T
 
OOP-1.pptx
OOP-1.pptxOOP-1.pptx
OOP-1.pptx
iansebuabeh
 
Different paradigms for problem solving.pptx
Different paradigms for problem solving.pptxDifferent paradigms for problem solving.pptx
Different paradigms for problem solving.pptx
iitjeesooraj
 
Regex,functions, inheritance,class, attribute,overloding
Regex,functions, inheritance,class, attribute,overlodingRegex,functions, inheritance,class, attribute,overloding
Regex,functions, inheritance,class, attribute,overloding
sangumanikesh
 
Oop(object oriented programming)
Oop(object oriented programming)Oop(object oriented programming)
Oop(object oriented programming)
geetika goyal
 
LECTURE NOTES ON Object Oriented Programming Using C++
LECTURE NOTES ON Object Oriented Programming Using C++LECTURE NOTES ON Object Oriented Programming Using C++
LECTURE NOTES ON Object Oriented Programming Using C++
SandeepAwasthi15
 
Chapter1 introduction
Chapter1 introductionChapter1 introduction
Chapter1 introduction
Jeevan Acharya
 
2nd PUC computer science chapter 6 oop concept
2nd PUC computer science chapter 6   oop concept2nd PUC computer science chapter 6   oop concept
2nd PUC computer science chapter 6 oop concept
Aahwini Esware gowda
 
Introduction to oop with c++
Introduction to oop with c++Introduction to oop with c++
Introduction to oop with c++
Shruti Patel
 
General OOP Concepts
General OOP ConceptsGeneral OOP Concepts
General OOP Concepts
Praveen M Jigajinni
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
Nilesh Dalvi
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
nikshaikh786
 
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPUUNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
ApurvaLaddha
 
Oops ppt
Oops pptOops ppt
Oops ppt
abhayjuneja
 
Chapter1
Chapter1Chapter1
Chapter1
jammiashok123
 
object oriented programming(PYTHON)
object oriented programming(PYTHON)object oriented programming(PYTHON)
object oriented programming(PYTHON)
Jyoti shukla
 
IET307 OOP - object oriented programming concepts.pptx
IET307 OOP - object oriented programming concepts.pptxIET307 OOP - object oriented programming concepts.pptx
IET307 OOP - object oriented programming concepts.pptx
BasithAb2
 
OOSD1-unit1_1_16_09.pptx
OOSD1-unit1_1_16_09.pptxOOSD1-unit1_1_16_09.pptx
OOSD1-unit1_1_16_09.pptx
ShobhitSrivastava15887
 
Introduction to Object oriented Programming basics
Introduction to Object oriented Programming basicsIntroduction to Object oriented Programming basics
Introduction to Object oriented Programming basics
SwatiAtulJoshi
 
POP vs OOP Introduction
POP vs OOP IntroductionPOP vs OOP Introduction
POP vs OOP Introduction
Hashni T
 
Different paradigms for problem solving.pptx
Different paradigms for problem solving.pptxDifferent paradigms for problem solving.pptx
Different paradigms for problem solving.pptx
iitjeesooraj
 
Regex,functions, inheritance,class, attribute,overloding
Regex,functions, inheritance,class, attribute,overlodingRegex,functions, inheritance,class, attribute,overloding
Regex,functions, inheritance,class, attribute,overloding
sangumanikesh
 
Oop(object oriented programming)
Oop(object oriented programming)Oop(object oriented programming)
Oop(object oriented programming)
geetika goyal
 
LECTURE NOTES ON Object Oriented Programming Using C++
LECTURE NOTES ON Object Oriented Programming Using C++LECTURE NOTES ON Object Oriented Programming Using C++
LECTURE NOTES ON Object Oriented Programming Using C++
SandeepAwasthi15
 
2nd PUC computer science chapter 6 oop concept
2nd PUC computer science chapter 6   oop concept2nd PUC computer science chapter 6   oop concept
2nd PUC computer science chapter 6 oop concept
Aahwini Esware gowda
 
Introduction to oop with c++
Introduction to oop with c++Introduction to oop with c++
Introduction to oop with c++
Shruti Patel
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
Nilesh Dalvi
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
nikshaikh786
 
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPUUNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
ApurvaLaddha
 
object oriented programming(PYTHON)
object oriented programming(PYTHON)object oriented programming(PYTHON)
object oriented programming(PYTHON)
Jyoti shukla
 
IET307 OOP - object oriented programming concepts.pptx
IET307 OOP - object oriented programming concepts.pptxIET307 OOP - object oriented programming concepts.pptx
IET307 OOP - object oriented programming concepts.pptx
BasithAb2
 
Introduction to Object oriented Programming basics
Introduction to Object oriented Programming basicsIntroduction to Object oriented Programming basics
Introduction to Object oriented Programming basics
SwatiAtulJoshi
 
Ad

Recently uploaded (20)

May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
sebastianku31
 
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbbTree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
RATNANITINPATIL
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
The first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptxThe first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptx
Mayank Mathur
 
Call For Papers - International Journal on Natural Language Computing (IJNLC)
Call For Papers - International Journal on Natural Language Computing (IJNLC)Call For Papers - International Journal on Natural Language Computing (IJNLC)
Call For Papers - International Journal on Natural Language Computing (IJNLC)
kevig
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)
pelumiadigun2006
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
gerogepatton
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdfIrja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus
 
Software Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance OptimizationSoftware Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance Optimization
kiwoong (daniel) kim
 
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
ijscai
 
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptxFINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
kippcam
 
International Journal of Advance Robotics & Expert Systems (JARES)
International Journal of Advance Robotics & Expert Systems (JARES)International Journal of Advance Robotics & Expert Systems (JARES)
International Journal of Advance Robotics & Expert Systems (JARES)
jaresjournal868
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
FISICA ESTATICA DESING LOADS CAPITULO 2.
FISICA ESTATICA DESING LOADS CAPITULO 2.FISICA ESTATICA DESING LOADS CAPITULO 2.
FISICA ESTATICA DESING LOADS CAPITULO 2.
maldonadocesarmanuel
 
22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank
Guru Nanak Technical Institutions
 
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
sebastianku31
 
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbbTree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
Tree_Traversals.pptbbbbbbbbbbbbbbbbbbbbbbbbb
RATNANITINPATIL
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
The first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptxThe first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptx
Mayank Mathur
 
Call For Papers - International Journal on Natural Language Computing (IJNLC)
Call For Papers - International Journal on Natural Language Computing (IJNLC)Call For Papers - International Journal on Natural Language Computing (IJNLC)
Call For Papers - International Journal on Natural Language Computing (IJNLC)
kevig
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)
pelumiadigun2006
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
gerogepatton
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdfIrja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus
 
Software Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance OptimizationSoftware Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance Optimization
kiwoong (daniel) kim
 
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
ijscai
 
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptxFINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
kippcam
 
International Journal of Advance Robotics & Expert Systems (JARES)
International Journal of Advance Robotics & Expert Systems (JARES)International Journal of Advance Robotics & Expert Systems (JARES)
International Journal of Advance Robotics & Expert Systems (JARES)
jaresjournal868
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
FISICA ESTATICA DESING LOADS CAPITULO 2.
FISICA ESTATICA DESING LOADS CAPITULO 2.FISICA ESTATICA DESING LOADS CAPITULO 2.
FISICA ESTATICA DESING LOADS CAPITULO 2.
maldonadocesarmanuel
 
Ad

Object oriented programming in python

  • 1. UNIT-V Object Oriented Programming Subject :PPS Subject Teacher :Ms. Mhaske N.R.
  • 2. Programming Paradigm lA fundamental style of programming that defines how the structure and basic elements of a computer program will be built. lStyle of writing programs and set of capabilities and limitations of a PL has depends on programming paradigm it supports. lPP can be classified as follows: 1. Monolithic Programming 2. Procedural Programming 3. Structured Programming 4. Object Oriented Programming lEach of these paradigms has its own strengths and weaknesses lNo single paradigm can suit all applications. le.g. for designing computation intensive problems, procedure oriented programming is preferred.
  • 3. Monolithic Programming lPrograms written using monolithic programming languages such as assembly language and BASIC consists of global data and sequential code. lGlobal data can be accessed and modified from any part of program. lSequential code is one in which all instructions are executed in the specified sequence. lMonolithic programs have just one program module. lAll the actions required to complete a task are embedded within same application itself. lThis makes the size of the program large and also makes it difficult to debug and maintain. lUsed only for small and simple applications MOV AX, A ADD AX, B MOV SUM, AX JMP STOP ………. STOP : EXIT ADB 10 BDB 20 SUM DB? Global data Sequential code with jmp instruction
  • 4. Procedural Programming lIn procedure language, a program is divided into n number of subroutines that access global data. lTo avoid repetition of code, each subroutine performs a well defined task. lA subroutine that needs the service provided by another subroutine can call that subroutine. lAdvantages: l1. goal is to write correct program l2. easier to write as compared to monolithic lDisadvantages: l1. writing program is complex l2. No concept of reusability l3. require more time and effort l4. difficult to maintain l5. global data may get altered. Global data Program Subprogram Structure of procedural program
  • 5. Structured Programming lAlso referred as modular programming. lSuggested by mathematician Corrado Bohm and Guiseppe Jacopini. lSpecifically designed to enforce a logical structure on the program to make it more efficient and easier to understand and modify. lTop-down approach lOverall program structure is broken down into separate modules. lThis allows the code to be loaded into memory more efficiently and also reused in other programs. lModules are coded separately and once module is written and tested , it is then integrated with other modules to form overall program. Global data Program Modules Structured Program
  • 6. Object Oriented Programming lIt treats data as a critical element in program development and restricts its flow freely around the system. lTask based and data based lAll the data and tasks are grouped together in entities known as objects. lIt uses routines provided in the object. lEvery object contains some data and the operations, methods or functions that operate on that data. lIn this approach, the list is considered an object consisting of the list, along with a collection of routines for manipulating the list. Object1 Object 2 Object 3 Object 4 Objects of a Program interact by sending messages to each other
  • 7. Object Oriented Programming lPrograms are data centered. lPrograms are divided into objects. lFunctions that operate on data are tied together with the data. lData is hidden and not accessible by external functions. lNew data and functions can be easily added as and when required. lFollows a bottom-up approach. Methods/functions Private data Object
  • 8. PROCEDURAL ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING In procedural programming, program is divided into small parts called functions. In object oriented programming, program is divided into small parts called objects. Procedural programming follows top down approach. Object oriented programming follows bottom up approach. There is no access specifier in procedural programming. Object oriented programming have access specifiers like private, public, protected etc. Adding new data and function is not easy. Adding new data and function is easy. Procedural programming does not have any proper way for hiding data so it is less secure. Object oriented programming provides data hiding so it is more secure. In procedural programming, overloading is not possible. Overloading is possible in object oriented programming. In procedural programming, function is more important than data. In object oriented programming, data is more important than function. Procedural programming is based on unreal world. Object oriented programming is based on real world. Examples: C, FORTRAN, Pascal, Basic etc. Examples: C++, Java, Python, C# etc.
  • 9. Features of OOP 1.Classes 2.Objects 3.Methods 4.Message passing 5.Inheritance 6.Polymorphism 7.Containership 8.Reusability 9.Delegation 10.Data abstraction and encapsulation.
  • 10. Classes lA class is used to describe something in the world, such as occurrences, things, external entities, etc. lA class provides a template or blueprint that describes the structure and behavior of a set of similar objects. le.g. lConsider class student with function showdata() and attributes namely, rollno, name, and course. lOnce a class is declared, programmer can create any number of objects of that class. lClass defines properties and behavior of objects. lA class is a collection of objects lIt is a user defined datatype that behaves same as the built in datatypes. class student: def __init__(self, rollno, name,course): self.rollno=rollno self.name=name self.course=course def showdata(self): print(“Rollno=“, self.rollno) print(“Name=“, self.name) print(“Course=“, self.course)
  • 11. Objects lObject is an instance of a class. lEvery object contains some data and functions. lThese methods store data in variables and respond to the messages that they receive from other objects by executing their methods. lWhile a class is a logical structure, an object is a physical actuality. lTo create object: Obj_nmae=class_name() To create an object of class student, Stud=student() Object name Attribute 1 Attribute 2 ……….. Attribute n Function 1 Function 2 ………… Function n Representation of an object
  • 12. Class method and self argument Exactly same as ordinary function but with one difference Class methods must have the first argument named as self. You do not pass a value for this parameter when you call the method. Python provides its value automatically. The self argument refers to the object itself. That is, the object that has called the method. even if a method that takes no arguments, it should be defined to accept the self. Since the class methods uses self, they require an object or instance of the class to be used. For this reason, they are often referred to as instance methods.
  • 13. The __init__ method(the class constructor) The __init__ method has a special significance in Python classes. It is automatically executed when an object of a class is created. The method is useful to initialize the variables of the class object. __init__ is prefixed as well as suffixed by double underscores. e.g. class ABC()  def __init__(self, val)  print(“in class method…….”)  self.val=val  print(“the value=”, val) obj=ABC(10) OUTPUT: in class method……. The value=10 In the __init__ method we define a variable as self.val which has exactly the same name as that specified in the argument list. Though the two variables have the same name, they are entirely different variables. The self.val belongs to the newly created object. __init__ method is automatically involved when the object of the class is created.
  • 14. Method and message passing lA method is a function associated with a class. lIt defines the operation that the object can execute when it receives a message. lOnly methods of the class can access and manipulate the data stored in an instance of the class. lTwo objects can communicate with each other through messages. lAn object asks another object to invoke one of its methods by sending it a message. Sender object Receiver object
  • 15. Inheritance lA new classis created from an existing class lNew class known as subclass, contains the attributes and methods of the parent class. lThe new class known as derived class in herits the attributes and behavior of the preexisting class which is referred as superclass or parent class lTherefore inheritance relation relation is also called as ‘is-a’ relation. lAdvantage : ability to reuse the code e.g. class student has data members rollno, name, course and methods getdata(), setdata(). We can inherit two classes from student class, namely UG and PG students. These two classes will have all the properties and methods of class students and in addition to that will have even more members. Parent features Parent + child features Parent, base or super class Child, derived or subclass
  • 16. Polymorphism lRefers to having several different forms. lIt is related to methods. lIn Python, polymorphism exists when a number of subclasses is defined which have methods of same name. lA function can use objects of any of the polymorphic classes irrespective of the fact that these classes are individually distinct. lPolymorphism can also be applied to operators. le.g. a+b will give result of adding a and b. lWhen we overload the +operator to be used with strings, then result is concatenation of two strings.
  • 17. Containership lIs the ability of a class to contain objects of one of more classes as member data. le. g. Class One an have object of class Two as its data member. lThis would allow the object of class One to call the public functions of class Two. lHere Class One becomes the container, whereas class Two becomes the contained class. lContainership is also called composition because class Oneiscomposed of class Two. lIt represents ‘has-a’ relationship.
  • 18. Reusability lMeans developing codes that can be reused either in same program or in different programs. lReusability is attained through inheritance, containership and polymorphism.
  • 19. encapsulation lEncapsulation defines three access levels: 1.Public: any data or function can be accessed by any function belonging to any class. This is the lowest level of data protection. 2. Protected: any data or function can be accessed only by that class or by any class that is inherited from it. 3. Private: any data or function can be accessed only by that class in which it is declared. This is the highest level of data protection.
  • 20. Delegation lIn delegation more than one object is involved in handling request. lThe object that receives the request for a service, delegate it to another object called its delegate. lDelegation is based on the property that a complex object is made of several simpler objects. le. g. our body is made up of brain, heart, hand, eyes etc. the functioning of the whole body as a system rests on correct functioning of the parts it is composed of. lIn delegation, they have ‘has-a’ relationship.
  • 21. Data abstraction and encapsulation lRefer to the process by which data and functions are defined in such a way that only essential details are revealed and the implementation details are hidden. lThe main focus of data abstraction is to separate the interface and the implementation of a program. le.g. as user of television set, we can switch it on or off, change the channel, set the volume without knowing the details about how its functionality has been implemented. lClasses provide public methods to the outside world to provide the functionality of the object or to manipulate the objects data. lData encapsulation also called data hiding. lData hiding is the technique of packing data and functions into a single component to hide implementation details of a class from the users. lTherefore encapsulation prevents data access by any function that is not specified in the class. lThis ensures integrity of the data contained in the object.