桥接模式(python)
2024-10-19 16:52:37
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}')
测试:
最新文章
- 从零开始编写自己的C#框架(5)——三层架构介绍
- 一个日期的下一个星期五 next_date
- 《python核心编程》笔记——文件的创建、读取和显示
- zoj1665 dij变形
- 联系旭日150安装CentOS5.X版本手记
- iOS - UITabBarController
- 使用ASP.Net WebAPI构建REST服务(六)——Self-Host
- 离线破win2003域账号密码(更新域数据库不在默认路径的情况)
- UVA 10603 Fill(正确代码尽管非常搓,网上很多代码都不能AC)
- 高精度运算专题1-加法运算(The addition operation)
- Lintcode360 Sliding Window Median solution 题解
- Ansible自动化运维工具-上
- final和static关键字
- Six advantages of Nissan consult 3 diagnostic tool
- SQL——查询一段时间内每天的数据,按天将数据封装进行封存
- Linux 动态链接库(.so)的使用
- TextView UI美化-------自适应字体控件
- <;数据结构系列1>;封装自己的数组——手写动态泛型数组(简化版ArrayList)
- C#继承IDisposable释放资源
- PHP爬取知乎日报图片显示不了问题
热门文章
- Tomcat简单介绍
- 【力扣】649. Dota2 参议院
- Moment.js使用笔记
- 热部署详细步骤---&#183;>; 小热身!
- 30个类手写Spring核心原理之AOP代码织入(5)
- Redis单点到集群迁移
- 什么是mysql innodb cluster?
- LuoguB2147 求 f(x,n) 题解
- IDEA启动报错:Error:java: Compilation failed: internal java compiler error
- java.lang.StackOverflowError报错