SlideShare a Scribd company logo
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

Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
Vibrant Technologies & Computers
 
C++ programming
C++ programmingC++ programming
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
CS3391 -OOP -UNIT – I NOTES FINAL.pdf
CS3391 -OOP -UNIT – I  NOTES FINAL.pdfCS3391 -OOP -UNIT – I  NOTES FINAL.pdf
CS3391 -OOP -UNIT – I NOTES FINAL.pdf
AALIM MUHAMMED SALEGH COLLEGE OF ENGINEERING
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
Arzath Areeff
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
Ahmed Farag
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
Md.Al-imran Roton
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
Web technology lab manual
Web technology lab manualWeb technology lab manual
Web technology lab manual
neela madheswari
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
Prof. Dr. K. Adisesha
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
colleges
 
Python programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphismPython programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphism
Emertxe Information Technologies Pvt Ltd
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objects
ITNet
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
Thooyavan Venkatachalam
 
Differences between c and c++
Differences between c and c++Differences between c and c++
Differences between c and c++
starlit electronics
 

What's hot (20)

Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
CS3391 -OOP -UNIT – I NOTES FINAL.pdf
CS3391 -OOP -UNIT – I  NOTES FINAL.pdfCS3391 -OOP -UNIT – I  NOTES FINAL.pdf
CS3391 -OOP -UNIT – I NOTES FINAL.pdf
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
 
Web technology lab manual
Web technology lab manualWeb technology lab manual
Web technology lab manual
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Python programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphismPython programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphism
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objects
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Differences between c and c++
Differences between c and c++Differences between c and c++
Differences between c and c++
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
 

Similar to Object oriented programming in python

PHP OOP Lecture - 01.pptx
PHP OOP Lecture - 01.pptxPHP OOP Lecture - 01.pptx
PHP OOP Lecture - 01.pptx
Atikur Rahman
 
12th ip CBSE chapter 4 oop in java notes complete
12th ip CBSE  chapter 4 oop in java notes complete12th ip CBSE  chapter 4 oop in java notes complete
12th ip CBSE chapter 4 oop in java notes complete
Harish Gyanani
 
Python-Classes.pptx
Python-Classes.pptxPython-Classes.pptx
Python-Classes.pptx
Karudaiyar Ganapathy
 
The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
POP vs OOP Introduction
POP vs OOP IntroductionPOP vs OOP Introduction
POP vs OOP Introduction
Hashni T
 
Object Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft DeveloperObject Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft Developer
Lee Greffin
 
Chapter1 introduction
Chapter1 introductionChapter1 introduction
Chapter1 introduction
Jeevan Acharya
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
ACCESS Health Digital
 
Principles of OOPs.pptx
Principles of OOPs.pptxPrinciples of OOPs.pptx
Principles of OOPs.pptx
LakshyaChauhan21
 
Oops
OopsOops
Unit 5.ppt
Unit 5.pptUnit 5.ppt
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptxOBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
Maharshi Dayanand University Rohtak
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
Sudip Simkhada
 
1 intro
1 intro1 intro
1 intro
abha48
 
MCA NOTES.pdf
MCA NOTES.pdfMCA NOTES.pdf
MCA NOTES.pdf
RAJASEKHARV10
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
AnmolVerma363503
 
Chapter1
Chapter1Chapter1
Chapter1
jammiashok123
 
OOPS_Unit_1
OOPS_Unit_1OOPS_Unit_1
OOPS_Unit_1
Shipra Swati
 

Similar to Object oriented programming in python (20)

PHP OOP Lecture - 01.pptx
PHP OOP Lecture - 01.pptxPHP OOP Lecture - 01.pptx
PHP OOP Lecture - 01.pptx
 
12th ip CBSE chapter 4 oop in java notes complete
12th ip CBSE  chapter 4 oop in java notes complete12th ip CBSE  chapter 4 oop in java notes complete
12th ip CBSE chapter 4 oop in java notes complete
 
Python-Classes.pptx
Python-Classes.pptxPython-Classes.pptx
Python-Classes.pptx
 
The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
 
POP vs OOP Introduction
POP vs OOP IntroductionPOP vs OOP Introduction
POP vs OOP Introduction
 
Object Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft DeveloperObject Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft Developer
 
My c++
My c++My c++
My c++
 
Chapter1 introduction
Chapter1 introductionChapter1 introduction
Chapter1 introduction
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
 
Principles of OOPs.pptx
Principles of OOPs.pptxPrinciples of OOPs.pptx
Principles of OOPs.pptx
 
Oops
OopsOops
Oops
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptxOBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
1 intro
1 intro1 intro
1 intro
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
MCA NOTES.pdf
MCA NOTES.pdfMCA NOTES.pdf
MCA NOTES.pdf
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Chapter1
Chapter1Chapter1
Chapter1
 
OOPS_Unit_1
OOPS_Unit_1OOPS_Unit_1
OOPS_Unit_1
 

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
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
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
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
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
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
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
 
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
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 

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
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
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
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
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
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
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
 
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
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 

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.