You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1847,6 +1848,148 @@ Python use naming conventions to indicate the intended level of access:
1847
1848
obj.access_protected()
1848
1849
```
1849
1850
1851
+
#### Abstract class
1852
+
1853
+
An abstract class can be considered 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.
1854
+
1855
+
A class that contains one or more abstract methods is called an **abstract class**. An abstract method is a method that has a delcaration but does not have an implementation.
1856
+
1857
+
We use abstract class while we are designing large functional units or when we want to provide a common interface for different implementations of a component.
1858
+
1859
+
##### Abstract base classes
1860
+
1861
+
By defining an abstract base class, you can define a common **Application Program Interface** (**API**) for a set of subclasses.
1862
+
1863
+
By default, Python does not provide abstract classes. Python comes with a module that provides the base for defining **Abstract Base Classes** (**ABC**) and that module name **ABC**.
1864
+
1865
+
* Example 01
1866
+
1867
+
```python
1868
+
from abc importABC, abstractmethod
1869
+
1870
+
classPolygon(ABC):
1871
+
# abstract method will be force to be implement in subclasses
product_record = ProductRecord("iPhone", 1000, "A new phone")
1987
+
print(product_record) # [PRODUCT] iPhone 1000 A new phone
1988
+
product_record.create()
1989
+
product_record.delete()
1990
+
print(ProductRecord.TAG()) # PRODUCT
1991
+
```
1992
+
1850
1993
### Polymorphism
1851
1994
1852
1995
Polymorphism means **many forms**, and in programming it refers to methods/functions/operators with the same name that can be executed on many object or classes.
0 commit comments