Lecture 4
Lecture 4
Introduction to Programming
LESSON 4
OOP in Python
© YCI – 2025.
BIT 1203 2/22/2025
OOP
2
◻ What is OOP?
Object oriented programming
Computer programming model that organizes
software design around data, or objects.
OOP focuses on the objects that developers want
to manipulate rather than the logic required to
manipulate them.
The main concept of OOPs is to bind the data and
the functions that work on that together as a
single unit so that no other part of the code can
access this data.
© YCI – 2025. 2/22/2025
OOP:- Building blocks of OOP
3
◻ Encapsulation:
All important information is contained inside an object
and only select information is exposed
Implementation and state of each object are privately
held inside a defined class.
◻ Abstraction.
Objects only reveal internal mechanisms that are
relevant for the use of other objects, hiding any
unnecessary implementation code.
The derived class can have its functionality extended.
This concept can help developers more easily make
additional changes or additions over time.
◻ Inheritance.
Relationships and subclasses between objects can be
assigned, enabling developers to reuse common logic
while still maintaining a unique hierarchy.
Allows defining parent and children classes.
◻ Polymorphism.
Objects are designed to share behaviors and they can take
on more than one form.
The program will determine which meaning or usage is
necessary for each execution of that object from a parent
class, reducing the need to duplicate code.
A child class is then created, which extends the
functionality of the parent class. Polymorphism allows
different types of objects to pass through the same
interface.
◻ A piece of code from which you can generate a unique object, where each
object is a single instance of the class.
Think of it as a blueprint or factory from which you can create individual objects.
A class is a collection of objects
◻ Object:
One unit of data plus code generated from a class as an instance of that class.
◻ Attribute:
A characteristic of an object that contains information about the object.
Also called a property of the object.
An attribute name is preceded by dot, as in member.username which may
contain the username for one site member.
◻ Method/function:
A Python function that’s associated with the class.
It defines an action that object can perform.
In an object, you call a method by preceding the method name with a dot, and
following it with a pair of parentheses.
■ For example member.archive() may be a method that archives (deactivates) the
member’s account.