装饰模式lua实现
来源:互联网 发布:ubuntu14.04安装mysql 编辑:程序博客网 时间:2024/04/20 01:28
Person = {}Decorator = {}function Person:new(o)o = o or {}setmetatable(o,self)self.__index = selfreturn o;endfunction Person:Show()print("我是人")endDecorator = Person:new{component = nil}function Decorator:Decorate(com)self.component = comendfunction Decorator:Show()print("我是装饰者")endShirt = Decorator:new()function Shirt:Show()print("最后衬衫")if self.component ~= nil thenself.component:Show()endendTrouser = Decorator:new()function Trouser:Show()print("然后裤子")if self.component ~= nil thenself.component:Show()endendShoe = Decorator:new()function Shoe:Show()print("先穿鞋子")if self.component ~= nil thenself.component:Show()endendperson = Person:new()shirt = Shirt:new()shirt:Decorate(person)trouser = Trouser:new()trouser:Decorate(shirt)shoe = Shoe:new()shoe:Decorate(trouser)shoe:Show()
代码输出:
先穿鞋子
然后裤子
最后衬衫
我是人
- 装饰模式lua实现
- 装饰模式--lua实现
- 装饰模式C++实现
- 装饰模式c++实现
- 装饰模式 C++实现
- 装饰模式C++实现
- 装饰模式----C++实现
- PHP实现装饰模式
- 装饰模式C++实现
- LUA实现状态模式
- 策略模式lua实现
- 代理模式lua实现
- 原型模式lua实现
- 外观模式lua实现
- 观察者模式lua实现
- 状态模式lua实现
- 适配器模式lua实现
- 迭代器模式lua实现
- 表格的导入
- CodeIgniter的中的一些基本数据库操作的demo
- phptest
- HDU 3697 暴力贪心
- iOS开发-UIAlerView
- 装饰模式lua实现
- Atomikos 性能提高8倍
- c++中函数参数传递(值传递、指针传递,引用传递)进一步认识
- ROWID
- 巧用Graphviz和pvtrace等工具可视化C函数调用
- VC6.0找不到控件工具条
- 查看tomcat为jvm分配的内存大小
- 3G模块PPPD拨号流程分析
- 系统架构师笔记(一)