PYTHON
9618
OBJECT ORIENTED PROGRAMMING
What is meant by OOP
Object Oriented programming is a
programming paradigm which based on
the concept of Objects and Classes
Objects
The Data and the Functions that belongs to
single entity can be grouped in single object
Each Object Hold Its Specific Information
Attributes
Player Name, x-position, y-position, Width, Height
Variables
Methods
collision, movement, Score-calculation
Functions
An object not only contains attributes but also
some action. Those actions are basically functions
What is the difference
between Class and Object
Class Object
Putting the data (attributes) and methods
together as a single unit is called Encapsulation
Declaration Of Methods and Attributes
There are two declaration methods in OOP
Public Private
The Attributes which are usually declared as PRIVATE
can only be accessed inside the class
The Methods which are usually declared as PUBLIC
can be accessed outside the class
NOTE : IN PYTHON YOU ARE SUPPOSE TO DECLARE ATTRIBUTES AS COMMENTS
What is a Constructor ?
Constructor are Functions which are used for
initializing the attributes / Properties of a class
def __init__():
Constructor In Python
QUESTION
P1 P2
name : "Ghost" name : "Ninja"
age : 21 age : 19
getAge () getAge ()
Player
Object 1 Object 2
name :
age :
displayName ()
Class
Defining a class
Creating Objects
Practice Question
How To Declare Attribute As
Private In Python
self.__LessonType
self.__Fees
self.__Name
Double UnderScore is used to make the attribute Private
Concept Of Inheritance
Part Time Employee Full Time Employee
Attributes Attributes
Name : String Name : String
Age : Integer Age : Integer
Hourlyrate: Integer MonthlyRate: Integer
Methods Methods
GetName() GetName()
DailyWage() YearlySalary()
Some Properties and Functions are repeated
Employee
Attributes
Name : String
Age : Integer
Methods
GetName()
Part Time Full Time
Attributes Attributes
Hourlyrate: Integer MonthlyRate: Integer
Methods Methods
DailyWage() YearlySalary()
What Is Meant By Inheritance ?
. The derived class can use the properties from the
Parent Class Without Redeclaring them
. The derived class can use the Methods from the
Parent Class Without Redeclaring them
. Can extend the Properties from the Parent Class
. Can extend the Methods from the Parent Class
super().
super() is a built-in Python function that provides a
way to access methods and attributes of a
superclass from a subclass. It is used to call the
implementation of a method that is defined in a
superclass, which has been overridden in a subclass.
How to identify if you should
use super(). or not
If you want to extend the methods used in Super Class
then you should use super().Method
Additionally is the Key Word to Identify
Containment
Containment is a fundamental concept in
Object-Oriented Programming (OOP) that
refers to the ability to include one object
inside another object.
Practice Question