from abc import ABCMeta, abstractmethod
class Shape(metaclass=ABCMeta): def __init__(self, color):
self.color = color
@abstractmethod
def draw(self):
pass class Color(metaclass=ABCMeta):
@abstractmethod
def paint(self, shape):
pass class Rectangle(Shape):
name = '长方形'
def draw(self):
self.color.paint(self) class Circle(Shape):
name = '圆'
def draw(self):
self.color.paint(self) class Line(Shape):
name = '线'
def draw(self):
self.color.paint(self) class Red(Color):
def paint(self,shape):
print(f'红色的{shape.name}') class Green(Color):
def paint(self,shape):
print(f'绿色的{shape.name}') class Blue(Color):
def paint(self,shape):
print(f'蓝色的{shape.name}')

测试:

最新文章

  1. 从零开始编写自己的C#框架(5)——三层架构介绍
  2. 一个日期的下一个星期五 next_date
  3. 《python核心编程》笔记——文件的创建、读取和显示
  4. zoj1665 dij变形
  5. 联系旭日150安装CentOS5.X版本手记
  6. iOS - UITabBarController
  7. 使用ASP.Net WebAPI构建REST服务(六)——Self-Host
  8. 离线破win2003域账号密码(更新域数据库不在默认路径的情况)
  9. UVA 10603 Fill(正确代码尽管非常搓,网上很多代码都不能AC)
  10. 高精度运算专题1-加法运算(The addition operation)
  11. Lintcode360 Sliding Window Median solution 题解
  12. Ansible自动化运维工具-上
  13. final和static关键字
  14. Six advantages of Nissan consult 3 diagnostic tool
  15. SQL——查询一段时间内每天的数据,按天将数据封装进行封存
  16. Linux 动态链接库(.so)的使用
  17. TextView UI美化-------自适应字体控件
  18. <数据结构系列1>封装自己的数组——手写动态泛型数组(简化版ArrayList)
  19. C#继承IDisposable释放资源
  20. PHP爬取知乎日报图片显示不了问题

热门文章

  1. Tomcat简单介绍
  2. 【力扣】649. Dota2 参议院
  3. Moment.js使用笔记
  4. 热部署详细步骤---·> 小热身!
  5. 30个类手写Spring核心原理之AOP代码织入(5)
  6. Redis单点到集群迁移
  7. 什么是mysql innodb cluster?
  8. LuoguB2147 求 f(x,n) 题解
  9. IDEA启动报错:Error:java: Compilation failed: internal java compiler error
  10. java.lang.StackOverflowError报错