Pattern

12) Flyweight Pattern

类别: Structural Pattern 问题/动机: 假若绿色是相同部分,占用1M内存 ,如果提取出来,众对象共享其内容,只占1M内存 ,否则占10M ,且随着对象增多,占用越来越多内存 ,无疑是浪费资源 A flyweight is an object that minimizes memo ......
Flyweight Pattern 12

13) Proxy Pattern

类别: Structural Pattern 问题: 操纵一个对象时碍手碍脚,与装饰者模式不同之处: 装饰者是接口方法,授权小 代理则是整个类,授权大 方案: 示例: public class ProxyPatternDemo { public static void main(final Stri ......
Pattern Proxy 13

15) Command pattern

类别: Behavioral Pattern 问题: 方案: 示例: import java.util.ArrayList; import java.util.List; public class CommandPatternDemo { public static void main(String ......
Command pattern 15

16) Interpreter pattern

类别: behavioral pattern 问题: Polish notation https://en.wikipedia.org/wiki/Polish_notation Abstract syntax tree https://en.wikipedia.org/wiki/Abstract_s ......
Interpreter pattern 16

17) Iterator pattern

类别: behavioral pattern 问题: Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. 方案 ......
Iterator pattern 17

14) chain of responsibility pattern

类别: behavioral pattern 问题: 高耦合,不灵活 if(){ }else if(){ }else if(){ } ... 方案: 示例: public class ChainOfResponsibilityPattern { public static void main(Str ......
responsibility pattern chain 14 of

cpp: Visitor Pattern

/*****************************************************************//** * \file Gold.h * \brief 访问者模式 Visitor Pattern C++ 14 行为模式 * 2023年6月8日 涂聚文 Geovi ......
Visitor Pattern cpp

cpp: Chain Of Responsibility Pattern

/*****************************************************************//** * \file PayrollProcessing.h * \brief 责任链模式Chain Of Responsibility Pattern 亦称: 职 ......
Responsibility Pattern Chain cpp Of

cpp: Memento Pattern

/*****************************************************************//** * \file ActorMemento.h * \brief 备忘录模式 Memento Pattern亦称:快照、Snapshot、Memento C++ ......
Memento Pattern cpp

compiler expression pattern match

编译器中经常需要用到pattern match。 那么如何实现呢? 比较直观的方法是使用递归。 以pattern match: y= a * (b + c) 为例。 首先,将其解析成一个抽象语法树:* a + b c 其次,递归match: match(y, pattern) => match(y, ......
expression compiler pattern match

3) Singleton pattern

类别: creational Pattern 问题/动机: 反复创建对象开销巨大耗时长消耗内存/重复使用 方案: 示例: // 1 class Demo1 { public final static Demo1 INSTANCE = new Demo1(); private Demo1() { if ......
Singleton pattern

4) Builder Pattern

类别: Creational pattern 问题: 构造函数入参超长易变 方案: 示例: public class BuilderPatternDemo { public static void main(String[] args) { Car.Builder builder = new Car ......
Builder Pattern

5) Prototype Pattern

类别: Creational Pattern 问题: 不想修改原对象状态,但需要依据当前数据进行计算 方案: 示例: public class PrototypePattern { public static void main(String[] args) { Movie movie = new ......
Prototype Pattern

6) Adapter Pattern

类别: Structural Pattern 问题: 什么是接口?按照标准提供服务,其他想要使用该接口的要按照该标准接入服务 什么是依赖?持有目标对象,拥有使用权(A use B) 数据线?数据线按USB标准接入充电宝,通过lightning 提供充电服务 手机?通过lightning标准接入数据线 ......
Adapter Pattern

7) Bridge Pattern

类别: Structural Patterns 问题: 连连看的问题 不使用桥接,要写81 个类,使用桥接,只需要18个类 方案: 示例: public class BridgePatternDemo { public static void main(String[] args) { Somebo ......
Pattern Bridge

9) Composite Pattern

类别: Structual Pattern 问题: 方案: 示例: import java.util.ArrayList; import java.util.List; public class CompositePatternDemo { public static void main(Strin ......
Composite Pattern

10) Decorator Pattern

类别: Structural Pattern 问题: 在不改变接口的前提下增加额外的服务 方案: 示例: public class DecoratorPatternDemo { public static void main(String[] args) { Shape circle = new C ......
Decorator Pattern 10

1) Factory method pattern

类别: Creational Pattern 问题/动机 如何创建一套子类的问题(父类引用指向子类实例) 情形1:一个方法返回一个具体的子类 极端情况:1万个子类需要一万个方法吗 极端情况:如过再扩展一万个子类,还需要再增加一万个方法吗 极端情况:虽然有一万个子类,但只需要用到其中一个,其他9999 ......
Factory pattern method

2) Abstract Factory Pattern

类别: Creational Pattern 问题/动机: 如何创建一套父类的问题 情形一:混淆,且不能察觉 // 下面这个方法本来是要建造一辆宝马汽车,但是因为零部件太多,粗心大意误用了奔驰的零件。 public Car createBMWCar(){ Part1 p1 = new com.bmw ......
Abstract Factory Pattern

8) Filter/Criteria Pattern

类别: Structual Pattern 问题: 方案: 示例: import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; public class Crit ......
Criteria Pattern Filter

cpp: Mediator Pattern

/*****************************************************************//** * \file ControlParent.h * \brief MediatorPattern 中介者模式 亦称: 调解人、控制器、Intermediary ......
Mediator Pattern cpp

cpp: Bridge Pattern

/*****************************************************************//** * \file Gold.h * \brief 桥接模式 Bridge Pattern C++ 14 * 2023年6月3日 涂聚文 Geovin Du Vi ......
Pattern Bridge cpp

cpp:Adapter Pattern

/*****************************************************************//** * \file GoldLogToFile.h * \brief 适配器模式Adapter Pattern 亦称: 封装器模式、Wrapper、Adapter ......
Adapter Pattern cpp

cpp: Proxy Pattern

/*****************************************************************//** * \file GoldWebSite.h * \brief 代理模式 ProxyPattern C++ 14 * 2023年5月31日 涂聚文 Geovin ......
Pattern Proxy cpp

解释器模式(Interpreter Pattern)

### 解释器模式(Interpreter Pattern) #### 一、定义 解释器模式(Interpreter Pattern)提供了评估语言的语法或表达式的方式,它属于行为型模式。这种模式实现了一个表达式接口,该接口解释一个特定的上下文。这种模式被用在 SQL 解析、符号处理引擎等。 给定一 ......
解释器 Interpreter Pattern 模式

cpp: Flyweight Pattern

/*****************************************************************//** * \file ChineseChess.h * \brief 享元模式 Flyweight Pattern 亦称: 缓存、Cache、Flyweight C ......
Flyweight Pattern cpp

Abstract Factory Pattern 抽象工厂模式简介与 C# 示例【创建型】【设计模式来了】

〇、简介 1、什么是抽象工厂模式? 一句话解释: 通过对抽象类和抽象工厂的一组实现,独立出一系列新的操作,客户端无需了解其逻辑直接访问。 抽象工厂模式(Abstract Factory Pattern)是一种创建型模式。它用于创建一组相关对象的家族。强调的是一组对象之间的协作关系,而不是单个对象之间 ......
模式 设计模式 示例 Abstract 工厂

cpp: State Pattern

/*****************************************************************//** * \file Gold.h * \brief State Pattern 状态模式 C++ 14 * 2023年5月29日 涂聚文 Geovin Du Vi ......
Pattern State cpp

Factory Method Pattern 工厂方法模式简介与 C# 示例【创建型】【设计模式来了】

〇、简介 1、什么是工厂方法模式? 一句话解释: 实体类和工厂类均为单独实现,不影响已实现的类,方便扩展。 工厂方法模式(Factory Method Pattern)是一种创建型模式,它允许客户端通过工厂方法来创建对象,而不是直接使用构造函数。这样可以让客户端代码更加灵活,同时保持实现的独立性。工 ......
模式 设计模式 示例 工厂 Factory

Pattern类

public class Pattern2 { public static void main(String[] args) { //1--创建对象 Pattern p=Pattern.compile("\\d+");// String[] str=p.split("我的qq邮箱是:20713570 ......
Pattern