OOP in Python 2 Lec 6
OOP in Python 2 Lec 6
in Python(2)
Lecture 6
Abstraction
Contents
•Abstraction definition
•Abstraction in Deep
•Use Abstract Base classes (ABC)
•Concrete Vs. Abstract (Classes & Methods)
•Example
•When? Why? Using Abstraction
•General Notes
• An abstract class can be considered as a blueprint for other classes. It allows you to create a set of
methods that must be created within any child classes built from the abstract class.
• A class which contains one or more abstract methods is called an abstract class.
• An abstract method is a method that has a declaration but does not have an implementation.
• While we are designing large functional units we use an abstract class. When we want to provide a
common interface for different implementations of a component, we use an abstract class.
Abstraction in Deep
• Car Speed
Eng. Size
Wheels
Eng. Size
Weight
• Abstract classes are incomplete because they have methods that have nobody. If
python allows creating an object for abstract classes then using that object if anyone
calls the abstract method, but there is no actual implementation to invoke. So we use
an abstract class as a template and according to the need, we extend it and build on it
before we can use it. Due to the fact, an abstract class is not a concrete class, it cannot
be instantiated. When we create an object for the abstract class it raises an error.