摘要:模板模式(Template Method Pattern) Define the skeleton of an algorithm in operations, deferring some steps to subclasses. Template Method lets subclasses r
阅读全文
摘要:抽象工厂模式(Abstract Factory Pattern) Provide an interface for creating families of related or dependent objects without specifying their concerete classes
阅读全文
摘要:工厂模式 Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation
阅读全文
摘要:单例模式(Singleton Pattern) Ensure a class has only one instance, and provide a global point of access to it.(确保只有一个实例, 而且自行实例化并向整个系统提供这个实例。) 模板 通用代码 publ
阅读全文
摘要:六大原则 单一职责原则: There should be no more than one reason for a class to change 最佳实践: 接口的设计一定要做到单一职责,类的设计尽量做到只有一个原因引起变化。 里氏替换原则: Functions that use pointer
阅读全文
摘要:策略模式:封装的是做一个事情的具体方法。封装以后可以选择任意的具体的方法。 实现: 各种具体方法使用Strategy接口,Context包含了strategy,通过改变它来调用不同的strategy 好处: 被封装的各种具体方法是一个class,可以被继承,可以根据需要被来控制程序而不改变程序本身的
阅读全文
摘要:Design Pattern : Singleton (设计模式:单例) 单例模式(Singleton):单例对象的类必须保证只有一个实例存在。许多时候整个系统只需要拥有一个的全局对象,这样有利于我们协调系统整体的行为。 几种实现方法: 方法一: 这种方法很简单,就是把instance变成priva
阅读全文