多个类抽取他比较像的部分,子类继承父类必须实现父类规定的方法
只能被继承,不能被实例化
所有方法全都规范起来,好处较低使用者的复杂度
#_*_coding:utf-8_*_
import abc
class Animal(metaclass=abc.ABCMeta): #只能被继承,不能被实例化
all_type='animal'
@abc.abstractmethod
def run(self):
pass
@abc.abstractmethod
def eat(self):
pass
# animal=Animal()
#继承Animal必须遵守你的规范,子类必须有这样的方法
class People(Animal):
def run(self):
print('people is running')
def eat(self):
print('people is eating')
class Pig(Animal):
def run(self):
print('people is walking')
def eat(self):
print('people is eating')
class Dog(Animal):
def run(self):
print('people is walking')
def eat(self):
print('people is eating')
peo1=People()
# pig1=Pig()
# dog1=Dog()
# #
# #
# peo1.eat()
# pig1.eat()
# dog1.eat()
#
print(peo1.all_type)