

demo.py
# 多态:一类事物具有多种形态,必须要有继承
# 多态性:多态性是指具有不同功能的函数可以使用相同的函数名
# txt文件 -- 双击
# MP4视频
from abc import ABCMeta,abstractmethod
class File(metaclass=ABCMeta):
@abstractmethod
def double_click(self):
pass
# 不同类的多态表现
# 继承抽象类
class txtFile(File):
def double_click(self): # 函数名尽量一致
print('打开txt,查看内容')
class exeFile(File):
def double_click(self):
print('打开excel,安装软件')
class mp4File(File):
def double_click(self):
print('打开mp4,打开视频')
#多态性:是指具有不同功能的函数可以使用相同的函数名
def double_click(file_obj):
file_obj.double_click()
txt = txtFile()
exe = exeFile()
mp4 = mp4File()
#调出实现多态性
double_click(txt)
double_click(exe)
double_click(mp4)