Abstraction
Abstraction in Python
• Abstraction is one of the important principles of object-
oriented programming.
• It refers to a programming approach by which only the
relevant data about an object is exposed, hiding all the
other details.
• This approach helps in reducing the complexity and
increasing the efficiency of application development.
Types of Python Abstraction
• There are two types of abstraction. One is data
abstraction, wherein the original data entity is hidden via
a data structure that can internally work through the
hidden data entities.
• Another type is called process abstraction. It refers to
hiding the underlying implementation details of a process.
Abstraction ??
• Did you learn Abstraction in Previous Programming
Language .
• If Yes _____OK .
• If No_______OK_OK.
• First we will learn that after that we will learn According to
Object Oriented Programming.
Abstraction
• Abstraction is the process of hiding the implementation
details from the user only the highlighted set of services
provided to the user.
• EX: Call Green Red
• When ever someone calling you have two choices either of
them.
• You know what is the impact of these two services buttons
but the internal implementation and code is hidden from
you .
Python Modules
User can Access services only
Backend/Internal Implementation Internal implementation hide
first.py second.py
add() sub() main.py
{ { add()
Sub()
} }
Python Modules Backend (first.py,
second.py)
first.py secon.py
Python Modules Services (Add, Sub)
main.py Output
Abstraction in OOP(python)
Abstraction
Abstract
Interface
Class
Abstract Class
• Abstract class is a class that contain one or more abstract method is
called Abstract class.
• An object of an Abstract class can not be created.
• Python provides abc module to work with Abstraction.
• We use @abstractmethod decorator to define abstract method.
• Abstraction used when Action is Common and Implementation is
Different.
Syntax
Interface
• Interface is nothing but abstract class which contain only abstract
method but does not have any normal method.
• We can not create object of interface.
• We use interface when action is same and implementation is
different.
• All child class should be inherit abstract method to override them.
Syntax
Example
Example
Example