Multiple inheritance interface class





#tiger walking swimming
#swan walking swimming fly
#oldying walk fly,
Import abc
from abc Import ABCMeta
class Swam_animal (the metaclass that = ABCMeta):
@ abc.abstractmethod
DEF SWAM (Self):
Pass
class Fly_animal (the metaclass that = ABCMeta):
@abc. AbstractMethod
DEF Fly (Self):
Pass
class Walk_animal (= the metaclass that ABCMeta):
@ abc.abstractmethod
DEF Walk (Self):
Pass

class Tiger (Walk_animal, Swam_animal):
Pass
class oldying (Fly_animal, Walk_animal):
Pass

class Swan (Walk_animal, Swam_animal, Fly_animal):
Pass

principle # Interface isolation interface class principle, be dedicated to a plurality of interfaces, without using a single interface, the client is not dependent on the interface that are not required

# Abstract class can only be inherited, can not be instantiated
# abstract class are generally single inheritance, the functions are the same, so the parent can have some simple parent class implements
case # multiple inheritance, since the functions more complex, it is not easy to abstract the same function written in the specific implementation in the parent class
# abstract class and interface class: object-oriented development specification
#python no interface classes, Java is no multiple inheritance
#python comes with more than inheritance, so with class implements an interface class
#python in support abstract classes, abstract classes in Java are all single inheritance, python multiple inheritance can, under normal circumstances is single inheritance
# but for multiple inheritance, use the interface in Java to solve the problem of multiple inheritance norms

Guess you like

Origin www.cnblogs.com/648071634com/p/11884655.html