设计模式学习
文章平均质量分 74
不能仅仅只做个码农而已
To follow the path:
look to the master,
follow the master,
walk with the master,
see through the master,
become the master.
展开
-
设计模式学习(创建型模式)—工厂方法模式(Factory Method)
1.工厂方法模式(Factory Method) 将程序中创建对象的操作,单独出来处理,创建一个产品的工厂接口,把实际的工作转移到具体的子类。大大提高了系统扩展的柔性,接口的抽象化处理给相互依赖的对象创建提供了最好的抽象模式。[java] view plaincopypublic class TestFactoryMethod { p原创 2014-11-01 15:56:18 · 791 阅读 · 0 评论 -
设计模式学习(创建型模式)—单例模式(Singleton)
单例模式(Singleton) 作用:用于改善全局变量和命名空间的冲突,可以说是一种改良了的全局变量。这种一个类只有一个实例,且提供一个访问全局点的方式,更加灵活的保证了实例的创建和访问约束。系统中只有一个实例,因此构造方法应该为私有 饿汉式:类加载时直接创建静态实例 懒汉式:第一次需要时才创建一个实例,那么newInstance方法要加同步 饿汉式比懒汉式要好,尽管资源利用率要差。但是不用同原创 2014-11-01 16:18:44 · 574 阅读 · 0 评论 -
设计模式学习(创建型模式)—建造模式(Builder)
建造模式(Builder) 将一个对象的内部表象和建造过程分割,一个建造过程可以造出不同表象的对象。可简化为模版方法模式.[java] view plaincopypublic class TestBuilder { public static void main(String[] args) { Bu原创 2014-11-01 17:25:14 · 701 阅读 · 0 评论 -
设计模式学习(创建型模式)—原型模式(ProtoType)
原型模式(ProtoType) 通过一个原型对象来创建一个新对象(克隆)。Java中要给出Clonable接口的实现,具体类要实现这个接口,并给出clone()方法的实现细节,这就是简单原型模式的应用。 浅拷贝:只拷贝简单属性的值和对象属性的地址 深拷贝:拷贝本对象引用的对象,有可能会出现循环引用的情况。可以用串行化解决深拷贝。写到流里再读出来,这时会是一个对象的深拷贝结果。原创 2014-11-03 14:07:55 · 675 阅读 · 0 评论 -
设计模式学习(结构型模式)—组合模式(Composite)
组合模式(Composite) 把整体和局部的关系用树状结构描述出来,使得客户端把整体对象和局部对象同等看待。[java] view plaincopyimport java.util.*; public class TestComposite { public static void main(Strin原创 2014-11-04 17:56:05 · 789 阅读 · 0 评论 -
设计模式学习(结构型模式)—装饰模式(Decorator)
装饰模式(Decorator) 以对客户透明的方式来扩展对象的功能。 用户根据功能需求随意选取组成对象的成分,通过方法的链式调用来实现。 可以给对象动态的增加功能,比继承灵活性更大。[java] view plaincopypublic class TestDecorator { public static原创 2014-11-05 11:58:37 · 653 阅读 · 0 评论 -
设计模式学习(创建型模式)—抽象工厂模式(Abstract Factory)
针对多个产品等级的情况,而工厂方法模式针对单一产品等级的情况。原创 2014-11-01 16:06:52 · 838 阅读 · 0 评论 -
设计模式学习(结构型模式)—适配器模式(Adapter)
适配器模式(Adapter) 在原类型不做任何改变的情况下,用一个适配器类把一个接口转成另一个接口,扩展了新的接口,灵活且多样的适配一切旧俗。这种打破旧框框,适配新格局的思想,是面向对象的精髓。以继承方式实现的类的 Adapter模式和以聚合方式实现的对象的Adapter模式,各有千秋,各取所长。原创 2014-11-03 16:02:24 · 784 阅读 · 0 评论 -
常用的android设计模式
常用的android设计模式有以下8种:单例、工厂、观察者、代理、命令、适配器、合成、访问者。原创 2014-12-18 13:41:48 · 1062 阅读 · 0 评论