一、工厂模式
目的:
创建功能类似的对象,创建后对其进行一些初始化的操作和处理;
提供给工厂客户一个创建对象的接口,根据输入的参数选择创建不同的对象;

实现方式


二、策略模式
在程序设计中一个功能有多种算法或者策略,我们可以根据环境或者条件的不同选择不同的算法或者策略来完成该功能;
其中一个典型应用就是表单验证:


三、中介者模式
对象之间直接通信太复杂的话会导致不良的紧耦合,修改代码维护困难。使用中介者模式让对象之间通过中介来通信,达到松耦合,有助提高维护性。
看个例子,按键小游戏

http://www.jspatterns.com/book/7/mediator.html
四、迭代器模式
迭代器模式通常用于提供一种简单的方法来访问复杂的自定义数据结构;

网友评论