SlideShare a Scribd company logo
1 of 13
OBJECT ORIENTED CONCEPTS
S c h o o l o f C S A
D h a n u s h R a j u C M
2
Agenda
• Object oriented
• Classes
• Objects
• Example
3
Why OOP?
With object oriented programming, the goal is
to encapsulate your code into logical, hierarchical
groupings using classes so that you can reason about your code
at a higher level
4
What is OOP?
Object oriented programming is a method of programming that attempts to
model some process or thing in the world as a class or object. OOP concepts
allow us to create specific interactions between objects. They make it
possible to reuse code without creating security risks or harming
performance and code readability
class - a blueprint for objects. Classes can contain methods (functions) and
attributes (similar to keys in a dict).
instance - objects that are constructed from a class blueprint that contain
their class's methods and properties.
Classes are created by keyword class, Attributes are the variables that
belong to a class.
Attributes are always public and can be accessed using the dot (.) operator.
Eg.: Myclass.Myattribute
5
SELF AND INIT
The self parameter is a reference to the current instance of the class, and is used
to access variables that belongs to the class.
It does not have to be named self , you can call it whatever you like, but it has to
be the first parameter of any function in the class
All classes have a function called __init__(), which is always executed when the
class is being initiated.
Use the __init__() function to assign values to object properties, or other
operations that are necessary to do when the object is being created:
6
Class definition syntax:
Class classname:
Statement-1
#class body
.
Statement-n
An object consists of :
State: It is represented by the attributes of an object. It also reflects the
properties of an object.
Behavior: It is represented by the methods of an object. It also reflects the
response of an object to other objects.
Identity: It gives a unique name to an object and enables one object to interact
with other objects.
class Car:
def __init__(self, name, mileage):
self.name = name
self. mileage = mileage
------------------------------------------------------------
------
obj2 = Car("Honda City",24.1)
7
The methods defined inside a class other than the constructor method are known as
the instance methods. Furthermore, we have two instance methods here- description()
and max_speed(). Let’s talk about them individually-
description()- This method is returning a string with the description of the car
such as the name and its mileage. This method has no additional parameter. This
method is using the instance attributes.
max_speed()- This method has one additional parameter and returning a string
displaying the car name and its speed.
Three important things to remember are-
1. You can create any number of objects of a class.
2. If the method requires n parameters and you do not pass the same number of
arguments then an error will occur.
3. Order of the arguments matters.
Thank You
9
ENCAPSULATION
Encapsulation helps with data security, allowing you to protect the data stored in a
class from system-wide access. As the name suggests, it safeguards the internal
contents of a class like a capsule.
You can implement encapsulation in Java by making the fields (class variables)
private and accessing them via their public getter and setter methods. JavaBeans are
examples of fully encapsulated classes.
Encapsulation in Java:
Restricts direct access to data members (fields) of a class
Fields are set to private
Each field has a getter and setter method
Getter methods return the field
Setter methods let us change the value of the field
10
The __init__ method :
The __init__ method is similar to constructors in C++ and Java.
It is run as soon as an object of a class is instantiated. The
method is useful to do any initialization you want to do with
your object
Self keyword:
self represents the instance of the class. By using the
“self” we can access the attributes and methods of the class
in python. It binds the attributes with the given arguments.
11
Encapsulation - the grouping of public and private attributes and methods into a
programmatic class, making abstraction possible
ENCAPSULATI
ON
12
ABSTRACTION
Abstraction - exposing only "relevant" data in a class interface, hiding private attributes and
methods (aka the "inner workings") from users
13

More Related Content

Similar to python.pptx

oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
ArpitaJana28
 

Similar to python.pptx (20)

oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
My c++
My c++My c++
My c++
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
 
Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
OOSD1-unit1_1_16_09.pptx
OOSD1-unit1_1_16_09.pptxOOSD1-unit1_1_16_09.pptx
OOSD1-unit1_1_16_09.pptx
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
 
Only oop
Only oopOnly oop
Only oop
 
Mca 504 dotnet_unit3
Mca 504 dotnet_unit3Mca 504 dotnet_unit3
Mca 504 dotnet_unit3
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHP
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2
 
Lesson 13 object and class
Lesson 13 object and classLesson 13 object and class
Lesson 13 object and class
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
 
Java basics
Java basicsJava basics
Java basics
 

Recently uploaded

Recently uploaded (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 

python.pptx

  • 1. OBJECT ORIENTED CONCEPTS S c h o o l o f C S A D h a n u s h R a j u C M
  • 2. 2 Agenda • Object oriented • Classes • Objects • Example
  • 3. 3 Why OOP? With object oriented programming, the goal is to encapsulate your code into logical, hierarchical groupings using classes so that you can reason about your code at a higher level
  • 4. 4 What is OOP? Object oriented programming is a method of programming that attempts to model some process or thing in the world as a class or object. OOP concepts allow us to create specific interactions between objects. They make it possible to reuse code without creating security risks or harming performance and code readability class - a blueprint for objects. Classes can contain methods (functions) and attributes (similar to keys in a dict). instance - objects that are constructed from a class blueprint that contain their class's methods and properties. Classes are created by keyword class, Attributes are the variables that belong to a class. Attributes are always public and can be accessed using the dot (.) operator. Eg.: Myclass.Myattribute
  • 5. 5 SELF AND INIT The self parameter is a reference to the current instance of the class, and is used to access variables that belongs to the class. It does not have to be named self , you can call it whatever you like, but it has to be the first parameter of any function in the class All classes have a function called __init__(), which is always executed when the class is being initiated. Use the __init__() function to assign values to object properties, or other operations that are necessary to do when the object is being created:
  • 6. 6 Class definition syntax: Class classname: Statement-1 #class body . Statement-n An object consists of : State: It is represented by the attributes of an object. It also reflects the properties of an object. Behavior: It is represented by the methods of an object. It also reflects the response of an object to other objects. Identity: It gives a unique name to an object and enables one object to interact with other objects. class Car: def __init__(self, name, mileage): self.name = name self. mileage = mileage ------------------------------------------------------------ ------ obj2 = Car("Honda City",24.1)
  • 7. 7 The methods defined inside a class other than the constructor method are known as the instance methods. Furthermore, we have two instance methods here- description() and max_speed(). Let’s talk about them individually- description()- This method is returning a string with the description of the car such as the name and its mileage. This method has no additional parameter. This method is using the instance attributes. max_speed()- This method has one additional parameter and returning a string displaying the car name and its speed. Three important things to remember are- 1. You can create any number of objects of a class. 2. If the method requires n parameters and you do not pass the same number of arguments then an error will occur. 3. Order of the arguments matters.
  • 9. 9 ENCAPSULATION Encapsulation helps with data security, allowing you to protect the data stored in a class from system-wide access. As the name suggests, it safeguards the internal contents of a class like a capsule. You can implement encapsulation in Java by making the fields (class variables) private and accessing them via their public getter and setter methods. JavaBeans are examples of fully encapsulated classes. Encapsulation in Java: Restricts direct access to data members (fields) of a class Fields are set to private Each field has a getter and setter method Getter methods return the field Setter methods let us change the value of the field
  • 10. 10 The __init__ method : The __init__ method is similar to constructors in C++ and Java. It is run as soon as an object of a class is instantiated. The method is useful to do any initialization you want to do with your object Self keyword: self represents the instance of the class. By using the “self” we can access the attributes and methods of the class in python. It binds the attributes with the given arguments.
  • 11. 11 Encapsulation - the grouping of public and private attributes and methods into a programmatic class, making abstraction possible ENCAPSULATI ON
  • 12. 12 ABSTRACTION Abstraction - exposing only "relevant" data in a class interface, hiding private attributes and methods (aka the "inner workings") from users
  • 13. 13