Abstract base class in python
from abc import ABC, abstractmethod
from abc import ABCMeta,abstractmethod
# class shape(metaclass=ABCMeta): for all version
class shape(ABC): #for higher version then 3.4
@abstractmethod
def function(self):
return 0
class Rectangle(shape):
type ="rectangle"
sides = 4
def __init__(self):
self.length = 5
self.breath = 6
def function(self):
return self.length * self.breath
rectanle = Rectangle()
print(rectanle.function())
Comments
Post a Comment