This repository covers 23 classic design patterns, divided into three categories:
- Singleton ⭐⭐⭐⭐⭐
- Factory Method ⭐⭐⭐⭐
- Abstract Factory ⭐⭐⭐
- Builder ⭐⭐⭐⭐
- Prototype ⭐⭐
- Adapter ⭐⭐⭐⭐
- Bridge ⭐⭐
- Composite ⭐⭐⭐
- Decorator ⭐⭐⭐⭐
- Facade ⭐⭐⭐⭐⭐
- Flyweight ⭐⭐
- Proxy ⭐⭐⭐⭐
- Chain of Responsibility ⭐⭐⭐
- Command ⭐⭐⭐⭐
- Interpreter ⭐
- Iterator ⭐⭐⭐⭐⭐
- Mediator ⭐⭐⭐
- Memento ⭐⭐
- Observer ⭐⭐⭐⭐⭐
- State ⭐⭐⭐
- Strategy ⭐⭐⭐⭐⭐
- Template Method ⭐⭐⭐⭐
- Visitor ⭐⭐
This repository provides dual-language implementations with both Rust and C++ examples. Each design pattern is implemented as an independent module.
Run the following command in the project root directory:
cargo buildFor example, to run singleton:
cargo run -p singletonReplace singleton with the crate name you want to run.
Run the following command in the project root directory:
makeFor example, to run command pattern:
make run singletonReplace singleton with the crate name you want to run.
make list # List all available C++ examples
make clean # Clean C++ build files
make help # Show help information本仓库涵盖了23种经典设计模式,分为三大类:
- 单例模式(Singleton)⭐⭐⭐⭐⭐
- 工厂方法模式(Factory Method)⭐⭐⭐⭐
- 抽象工厂模式(Abstract Factory)⭐⭐⭐
- 建造者模式(Builder)⭐⭐⭐⭐
- 原型模式(Prototype)⭐⭐
- 适配器模式(Adapter)⭐⭐⭐⭐
- 桥接模式(Bridge)⭐⭐
- 组合模式(Composite)⭐⭐⭐
- 装饰模式(Decorator)⭐⭐⭐⭐
- 外观模式(Facade)⭐⭐⭐⭐⭐
- 享元模式(Flyweight)⭐⭐
- 代理模式(Proxy)⭐⭐⭐⭐
- 责任链模式(Chain of Responsibility)⭐⭐⭐
- 命令模式(Command)⭐⭐⭐⭐
- 解释器模式(Interpreter)⭐
- 迭代器模式(Iterator)⭐⭐⭐⭐⭐
- 中介者模式(Mediator)⭐⭐⭐
- 备忘录模式(Memento)⭐⭐
- 观察者模式(Observer)⭐⭐⭐⭐⭐
- 状态模式(State)⭐⭐⭐
- 策略模式(Strategy)⭐⭐⭐⭐⭐
- 模板方法模式(Template Method)⭐⭐⭐⭐
- 访问者模式(Visitor)⭐⭐
本仓库提供 两种语言 实现,包含 Rust 和 C++ 示例。每个设计模式都实现为独立模块。
在项目根目录下执行:
cargo build以 singleton 为例:
cargo run -p singleton将 singleton 替换为你想运行的 crate 名称即可。
在项目根目录下执行:
make以命令模式为例:
make run singleton将 singleton 替换为你想运行的模式名称即可。
make list # 列出所有可用的 C++ 示例
make clean # 清理 C++ 构建文件
make help # 显示帮助信息