2013年7月13日

原型模式

摘要: > * 通过克隆创建对象 */class Sea {}class EarthSea extends Sea{}class MarsSea extends Sea{}class Plains {}class EarthPlains extends Plains{}class MarsPlains extends Plains{}class Forest {}class EarthForest extends Forest{}class MarsForest extends Forest{}class TerrainFactory { private $sea; private $fo... 阅读全文

posted @ 2013-07-13 14:04 mtima 阅读(196) 评论(0) 推荐(0) 编辑

facade模式

摘要: /** * 外观模式 * 为繁杂的操作提供干净的接口 *///阻止事件的默认行为和冒泡/** * 终止事件冒泡 * stopPropagation() * preventDefault() * 对以上两个操作进行外观封装,获取一个干净的接口。 */var myEvent = { stop: function(e) { e.stopPropagation(); e.preventDefault(); }};//跨浏览器封装var myEvent = { stop: function(e) { //其它浏览器 (typeof... 阅读全文

posted @ 2013-07-13 10:24 mtima 阅读(174) 评论(0) 推荐(0) 编辑

类继承模式

摘要: /** * 来自> * * 本人学习时整理了一遍 *//** * 类继承模式-默认模式 */function inherit (C, P) { C.prototype = new P;}//父构造函数function Parent(name) { this.name = name || "Adam";}//往父类构造函数的原型上添加一个方法Parent.prototype.say = function() { return this.name;}//子类构造函数function Child(name) { this.name = name;}inherit(Child 阅读全文

posted @ 2013-07-13 10:08 mtima 阅读(214) 评论(0) 推荐(0) 编辑

备忘模式

摘要: <?php/** * 备忘模式 * 即将函数的计算结果缓存,缓存计算量大的计算结果,避免重复计算。提高程序效率。 * * 备忘求阶乘 */function memo_func($n) { static $cache = array(); $selfName = __FUNCTION__; if ($n<=1) { return $cache[md5($n)] = 1; } else { return $cache[md5($n)] = $n*$selfName($n-1); }}for ($i=5; $i<100; $i++) { ... 阅读全文

posted @ 2013-07-13 09:09 mtima 阅读(148) 评论(0) 推荐(0) 编辑

导航