handling the internal details show the functionality is call abstraction in pyhton
ABC predefine abstract class it present in abc module in pyhton
NOTE: Make your class abstract class. your class must be extends the ABC predefine abstract class in python
from abc import ABC,abstractmethod class A10(ABC): @abstractmethod def getDebitCard(self): pass @abstractmethod def getCreditCard(self): pass class B10(A10): def getDebitCard(self,amount): return amount def getCreditCard(self,amount): return amount a10=A10() print(a10.getCreditCard(100000)) print(a10.getDebitCard(2000000))
TypeError: Can't instantiate abstract class A10 with abstract methods getCreditCard, getDebitCard
from abc import ABC,abstractmethod class A10(ABC): @abstractmethod def getDebitCard(self): pass @abstractmethod def getCreditCard(self): pass class B10(A10): def getDebitCard(self,amount): return amount def getCreditCard(self,amount): return amount b10=B10() print(b10.getCreditCard(100000)) print(b10.getDebitCard(2000000))
100000 2000000
from abc import ABC,abstractmethod class A10(ABC): @abstractmethod def getDebitCard(self): pass class B10(A10): def getDebitCard(self,amount): return amount class D10(A10): def getDebitCard(self,amount): return amount b1=B10() print(b1.getDebitCard(500000)) d2=D10() print(d2.getDebitCard(600000))
500000 600000
from abc import ABC,abstractmethod class A10(ABC): @abstractmethod def getDebitCard(self,message): pass @abstractmethod def getCreditCard(self,message): pass class B10(A10): def getDebitCard(self,message): return message b10=B10() print(b10.getDebitCard("By B10")) print(b10.getCreditCard("By D10")
TypeError: Can't instantiate abstract class B10 with abstract methods getCreditCard
from abc import ABC,abstractmethod class A10(ABC): @abstractmethod def getDebitCard(self,message): pass @abstractmethod def getCreditCard(self,message): pass class B10(A10): def getDebitCard(self,message): return message class D10(B10): def getCreditCard(self,message): return message d1=D10() print(d1.getDebitCard("By B10")) print(d1.getCreditCard("By D10"))
By B10 By D10
from abc import ABC,abstractmethod class CalAbc: def __init__(self,a,b): print("CalAbc") self.a=a self.b=b @abstractmethod def display(self): pass class CalImpl1(CalAbc): def display(self): return self.a+self.b class CalImpl2(CalAbc): def display(self): return self.a/self.b class CalImpl3(CalAbc): def display(self): return self.a*self.b class CalImpl4(CalAbc): def display(self): return self.a%self.b print(CalImpl1(100,200).display()); print(CalImpl1(153,2).display()); print(CalImpl1(100,300).display()); print(CalImpl1(153,2).display());
CalAbc 300 CalAbc 155 CalAbc 400 CalAbc 155