JavaScript6/ES6的设计模式实现

这是使用Javascript 6(ES6/ES2015)实现的四人帮GOF设计模式源码项目。主要包括:

适配器Adapter、职责链Chaining、命令Command、组合Composite、组合遍历器Composite Iterator、复合模式Compound (将一些设计模式使用在一起解决问题)、油漆匠Decorator、总管Facade、工厂Factory、
Iterator、懒加载赋值Lazy、模块Module、Module Revealed、模块多继承Multi-Inheritance ES6、MVC、Namespace、Nullify、观察Observer、代理Proxy、单例Singleton、状态State、策略Strategy、模板Template、Try-Finally。

以适配器模式为例,代码实现如下:


import MallardDuck from './MallardDuck';
import WildTurkey from './WildTurkey';
import TurkeyAdapter from './TurkeyAdapter';

let oMallardDuck = new MallardDuck();
let oWildTurkey = new WildTurkey();
let oTurkeyAdapter = new TurkeyAdapter(oWildTurkey);

oMallardDuck.fly();
oMallardDuck.quack();

oWildTurkey.fly();
oWildTurkey.gobble();

oTurkeyAdapter.fly();
oTurkeyAdapter.quack();

GitHub - tcorral/Design-Patterns-in- Design Patter
[该贴被banq于2016-06-07 10:18修改过]