(function(){
//门面
function addEvebtFacade(el,type,fn){
if(window.addEventListener){
//使用与火狐浏览器
alert(1);
el.addEventListener(type,fn,false);
}else if(window.attachEvent){
//适用于IE的
alert(2);
el.attachEvent("on"+type,fn);
}else{
alert(3);
el["on"+type] = fn;
}
}
document.write("<a id='but1' href='#'>click</a>");
var el = document.getElementById("but1");
addEvebtFacade(el,"click",function(){
alert("ok")
})
})()
/**
* 用2个DAO来体现门面模式
*/
(function(){
//人员类
var PersonDao = new Interface("PersonDao",["getInfo","learn",
"marry"]);
var Person = function(){
this.name = "YUNFENGCHENG";
this.address = "BEIJING";
this.getInfo = function(){
return "名字: "+this.name +" 地址: "+this.address;
}
this.learn = function(){
document.write("学习");
}
this.marry = function(){};
//验证实现的接口
Interface.ensureImplements(this,PersonDao);
}
//DOG DAO
var DogDao = new Interface("DogDao",["call","run","getInfo"]);
var Dog = function(){
this.name = "DAHUANG";
this.getInfo = function(){
return "狗狗的名字: "+this.name;
}
this.run = function(){};
this.call = function(){};
Interface.ensureImplements(this,DogDao);
}
//需求是现在需要给养的够办了相应宠物领养证件 需要人和狗狗的信息可以
//1.不用门面
//客户端程序
function action(person,dog){
//当做养狗证的号码
var r = "GG"+new Date().getDate()+Math.floor(Math.random()*11);
var str = "办证成功 :编号 "+r
+"<br>主人信息: "+person.getInfo()
+"<br>狗狗的信息: "+dog.getInfo();
document.write(str);
}
action(new Person(),new Dog());
document.write("<br>..........................");
//使用门面模式
//负载的事交给门面来做
function facade(person,dog){
//当做养狗证的号码
var r = "GG"+new Date().getDate()+Math.floor(Math.random()*11);
this.str = "办证成功 :编号 "+r
+"<br>主人信息: "+person.getInfo()
+"<br>狗狗的信息: "+dog.getInfo();
}
facade.prototype.action = function(){
return this.str;
}
//客户端程序
function action2(person,dog){
document.write(new facade(person,dog).action());
}
action2(new Person(),new Dog())
//用了门面模式客户端代码就变的如此的简单了
})()

最新文章

  1. 使用spring的@Scheduled注解执行定时任务,启动项目不输出警告
  2. poj 2528
  3. 开发Yii2过滤器并通过behaviors()行为调用
  4. VTK初学一,a_Vertex图形点的绘制
  5. numpy之sum
  6. Golang学习 - sync 包
  7. CentOS 7 minimal 版本安装后网络配置
  8. ORA-14400: inserted partition key does not map to any partition
  9. 基于visual Studio2013解决C语言竞赛题之0422牛顿迭代法
  10. No mapping found for HTTP request with URI [/HelloWeb/] in DispatcherServlet with name &#39;HelloWeb&#39; Spring MVC
  11. python3 爬 妹子图
  12. 一个不可思议的MySQL慢查分析与解决
  13. 移动端键盘密码输入框插件(jquery用于支付密码)
  14. python 可迭代对象 迭代器 生成器总结
  15. C# 导出Excel Table td 样式
  16. java 基础排序算法
  17. Druid中配置双数据库
  18. HttpServletResponse实现文件下载
  19. Codeforces Beta Round #94 (Div. 1 Only)B. String sam
  20. exe4j 安装

热门文章

  1. main()函数的形参
  2. cocos2d-x 显示触摸操作(显示水波点击效果,用于视频演示)
  3. generate the call load file
  4. SQL Search
  5. js --- 中字符串与unicode编码
  6. POJ - 3842 An Industrial Spy dfs(水)
  7. HTTP 各种特性应用(三)
  8. 如何更改AD域安全策略-密码必须符合复杂性要求
  9. 原型,构造函数,实例,__proto__
  10. TRIZ系列-创新原理-31-多孔材料原理