随笔分类 - 设计模式
摘要:1. 代理模式的定义和应用 1.1 代理模式的定义 Provide a surrogate or placeholder for another object to control access to it .(为其他对象提供一种代理以控制对这个对象的访问) 代理模式的类图如下: 代理模式也叫做委托
阅读全文
摘要:《设计模式之禅》读书笔记(四)之抽象工厂模式 一、抽象工厂模式的定义 Provide an Interface for creating families of related or dependent objects without specifying their concrete classe
阅读全文
摘要:一、缩小为简单工厂模式 考虑这样一个问题:一个模块仅需要一个工厂类,没有必要把它产生出来,使用静态的方法就可以了。类图如下 可以看出简单工厂模式,是把抽象的工厂类变为静态的工厂类,简化了类的创建过程。需要变更的源码仅仅是HumanFactory和NvWa类。之前的笔记中没给出书上的例子,考虑到只写出
阅读全文
摘要:工厂方法模式的定义为: Define an interface for creating an object , but let subclass decide which class to instantiate. Factory Method lets a class defer instant
阅读全文
摘要:单例模式是一个比较简单的模式,定义如下: Ensure a class has only one instance, and provide a global point of access to it.(确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例) 1.饿汉式 2.懒汉式 线
阅读全文