组合模式
来源:互联网 发布:风乎舞雩的乎 编辑:程序博客网 时间:2024/06/06 02:53
简单来说,就是一个复杂的对象里可以包含其他对象,
如下面
一个盒子里面可以放进其他东西
from abc import abstractmethodclass item: @abstractmethod def __init__(self,name,price): pass @abstractmethod def printprice(self): passclass pen(item): def __init__(self,name,price): self.name = name self.price = price def printprice(self): print "pen:{}$".format(self.price)class rule(item): def __init__(self,name,price): self.name = name self.price = price def printprice(self): print "rule:{}$".format(self.price)class box(item): def __init__(self,name,price): self.name = name self.price = price self.children = [] def printprice(self): print "box:{}$".format(self.price) for i in self.children: i.printprice() def add(self,items): if items: self.children.append(items)pen01 = pen('pen',1)rule01 = rule('rule',1)box01 = box('box',2)box01.add(pen01)box01.add(rule01)box01.printprice()
0 0
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- 组合模式
- Experimental Security Analysis of a Modern Automobile
- opensips函数
- Android Recovery:功能简介。Recovery模式介绍
- 20160331 UVA11806 Cheerleaders(组合数公式+容斥原理)
- python pep8
- 组合模式
- Bootstrap总结
- sql sever2012学习1 数据库与表的删除与创建
- java--静态变量,静态方法和静态类
- Python的函数参数传递:传值?引用?
- Intent传参
- 山东省第一届ACM省赛题——Balloons(搜索)
- 2016sdau课程练习专题一 1012 problemM
- K60学习笔记四:按键的多种操作