11.Python3接口继承

"""
    接口继承

    父类规定好咯----规范,不实现
    子类必须实现
    归一化
"""
import abc

class File(metaclass=abc.ABCMeta):

    @abc.abstractmethod
    def read(self):
        pass

    @abc.abstractmethod
    def write(self):
        pass


class Disk(File):

    def read(self):
        print("Disk read")

    def write(self):
        print("Disk write")



class Cdrom(File):

    def read(self):
        print("Cdrom read")

    def write(self):
        print("Cdrom write")


class Mem(File):

    def read(self):
        print("Mem read")

    def write(self):
        print("Mem write")


m1 = Mem()
m1.read()
m1.write()

你可能感兴趣的:(11.Python3接口继承)