What is Abstraction ?
             Abstraction is an Object-Oriented Programming (OOP) principle that hides implementation details and shows only what is necessary to the user.
             Abstraction focuses on what an object does, not how it does it.


Why Abstraction is Needed ?
  •                The same method or operreduce complexity.
  • Improve security enforce consistent structure
  • Separate interface from implementation
  • Support large and scalable applicationsation to behave differently based on the object or context.

Python implements abstraction using:

  • Abstract Classes
  • Abstract Methods
  • abc module

Abstract Class :

An abstract class is a class that:

  • cannot be instantiated

  • contains one or more abstract methods

  • acts as a blueprint for child classes


Abstract Method :

An abstract method is a method that:

  • has no implementation in the parent class

  • must be implemented in the child class


abc module :

To create abstract classes, Python provides the abc module.

Python
from abc import ABC, abstractmethod 


Example :

Python
from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def draw(self): pass class Circle(Shape): def draw(self): print("Drawing Circle") class Square(Shape): def draw(self): print("Drawing Square") c = Circle() s = Square() c.draw() s.draw() #output Drawing Circle Drawing Square