《23种设计模式 Lua篇》 - 中介者模式
来源:互联网 发布:ajax jquery json data 编辑:程序博客网 时间:2024/04/30 01:48
北漂生涯 房源都掌握在房屋中介手上,租房的只能通过中介去联系房东。 PS:北京的租房中介费是一个月房租啊~ 坑爹啊 有木有
一、Custom.lua 客户基类 房东和租房者 准确说都是中介的客户
--/**************************************************************************-- Copyright: www.SaintGrail.com-- Author: liu jing--- Date: 2014-08-27--- Description: 客户基类---**************************************************************************/Custom={}-- 客户名称Custom.name=nil-- 与客户打交道的房屋中介Custom.mediator=nil function Custom:new(_o) _o = _o or {} setmetatable(_o,self) self.__index=self return _oendfunction Custom:Notify(_str) self.mediator:Notify(_str,self)endfunction Custom:Say(_str) print(self.name.." get message :".._str)end
二、Mediator.lua 房屋中介 (掌握着双方的信息)
--/**************************************************************************-- Copyright: www.SaintGrail.com-- Author: liu jing--- Date: 2014-08-27--- Description: 中介者---**************************************************************************/-- 中介Mediator={}-- 房东Mediator.landlord=nil-- 租房者Mediator.tenant=nilfunction Mediator:new(_o) _o = _o or {} setmetatable(_o,self) self.__index = self return _oendfunction Mediator:Notify(_str,_obj) if _obj==self.landlord then self.tenant:Say(_str) else self.landlord:Say(_str) endend
三、 mian.lua 主函数
require ("Mediator")require ("Custom") local function main() -- 房地产 中介 local mediator = Mediator:new() -- 房东 local landlord = Custom:new() landlord.mediator=mediator landlord.name = "fangdong" -- 租房客 local tenant = Custom:new() tenant.mediator=mediator tenant.name = "fangke" mediator.landlord=landlord mediator.tenant=tenant tenant:Notify(" you fang zi ma?") landlord:Notify(" mei fang zi")endmain()
四、输出结果如下
Debugger v1.1.0Debugger: Trying to connect to 127.0.0.1:10000 ... Debugger: Connection succeed.fangdong get message : you fang zi ma?fangke get message : mei fang zi
0 0
- 《23种设计模式 Lua篇》 - 中介者模式
- 设计模式23篇:中介者模式
- 23种设计模式-中介者模式
- 中介者模式lua实现
- 【设计模式】中介者
- 中介者设计模式
- 设计模式-中介者
- 设计模式-中介者
- [设计]中介者模式
- 23种设计模式之中介者模式(Mediator)
- 23种设计模式(7):中介者模式
- 23种设计模式(7):中介者模式
- 23种设计模式(7):中介者模式
- 23种设计模式(7):中介者模式
- 23种设计模式(7):中介者模式
- 23种设计模式(7):中介者模式
- 23种设计模式(7):中介者模式
- 23种设计模式之中介者模式1
- hi3531交叉编译环境arm-hisiv100nptl-linux搭建过程
- 颜色选择,自定义颜色供选择
- android的intent使用方法
- 金庸武侠小说之我的见解
- VGA驱动
- 《23种设计模式 Lua篇》 - 中介者模式
- unity3d大型手游 可以打包obb文件
- iOS开发实战:Mailcore深度解析
- 设计模式六大原则(5):迪米特法则
- 关于时间复杂度
- linux printf 特殊输出实例
- 实例学习gcc+gdb+make
- Cocos2d-x教程(32)-quick-cocos2d-x 加密
- 二叉树后序遍历和层次遍历