PHPackages                             mr-jiawen/php-design - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. mr-jiawen/php-design

ActiveLibrary

mr-jiawen/php-design
====================

7113PHP

Since May 14Pushed 8y ago1 watchersCompare

[ Source](https://github.com/MrJiawen/php-design)[ Packagist](https://packagist.org/packages/mr-jiawen/php-design)[ RSS](/packages/mr-jiawen-php-design/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

php-23-design
=============

[](#php-23-design)

php的23种设计模式

下载命令
----

[](#下载命令)

```
composer require mr-jiawen/php-design:dev-master

```

第一部分 23种设计模式分类
--------------

[](#第一部分-23种设计模式分类)

> 设计模式分为：创建型模式， 结构型模式，行为型模式等23种设计模式。

注意:

1. 对象层面：处理对象之间的关系，决定于运行期。
2. 类层面：处理类的关系，决定于在编译期。

### 1.1 创建型

[](#11-创建型)

> `创建型设计模式`用于处理对象的实例化, 其构建对象以便能从实现系统解耦。

1. [工厂方法模式factory\_method](./Markdown/factory_method%EF%BC%88%E5%B7%A5%E5%8E%82%E6%96%B9%E5%BC%8F%E6%A8%A1%E5%BC%8F%EF%BC%89.md)
2. [抽象工厂模式abstract\_factory](./Markdown/abstract_factory(%E6%8A%BD%E8%B1%A1%E5%B7%A5%E5%8E%82%E6%A8%A1%E5%BC%8F).md)
3. [单例模式singleton](./Markdown/singleton(%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F).md)
4. [建造者模式builder](./Markdown/builder(%E5%BB%BA%E9%80%A0%E8%80%85%E6%A8%A1%E5%BC%8F).md)
5. [原型模式prototype](./Markdown/prototype(%E5%8E%9F%E5%9E%8B%E6%A8%A1%E5%BC%8F).md)

### 1.2 结构型

[](#12-结构型)

> `结构型设计模式`用于处理类和对象的组合,让不同的对象组成大规模的对象结构。

1. [适配器模式adapter](./Markdown/adapter(%E9%80%82%E9%85%8D%E5%99%A8%E6%A8%A1%E5%BC%8F).md)
2. [装饰器模式decorator](./Markdown/decorator(%E8%A3%85%E9%A5%B0%E5%99%A8%E6%A8%A1%E5%BC%8F).md)
3. [代理模式proxy](./Markdown/proxy(%E4%BB%A3%E7%90%86%E6%A8%A1%E5%BC%8F).md)
4. [门面模式facade](./Markdown/facade(%E9%97%A8%E9%9D%A2%E6%A8%A1%E5%BC%8F).md)
5. [桥接模式bridge](./Markdown/bridge(%E6%A1%A5%E6%8E%A5%E6%A8%A1%E5%BC%8F).md)
6. [合成模式composite(组合模式)](./Markdown/composite(%E5%90%88%E6%88%90%E6%A8%A1%E5%BC%8F).md)
7. [享元模式flyweight](./Markdown/flyweight(%E4%BA%AB%E5%85%83%E6%A8%A1%E5%BC%8F).md)

### 1.3行为型

[](#13行为型)

> `行为型设计模式`用于处理类的对象间通信，在对象中管理算法，关系，和责任。

1. [策略模式strategy](./Markdown/strategy(%E7%AD%96%E7%95%A5%E6%A8%A1%E5%BC%8F).md)
2. [模板方法模式template\_method](./Markdown/templateMethod(%E6%A8%A1%E6%9D%BF%E6%96%B9%E6%B3%95%E6%A8%A1%E5%BC%8F).md)
3. [观察者模式observer](./Markdown/observer(%E8%A7%82%E5%AF%9F%E8%80%85%E6%A8%A1%E5%BC%8F).md)
4. [迭代器模式iteration](./Markdown/iteration(%E8%BF%AD%E4%BB%A3%E5%99%A8%E6%A8%A1%E5%BC%8F).md)
5. [责任链模式responsibility\_chain](./Markdown/ResponsibilityChainPratice(%E8%B4%A3%E4%BB%BB%E9%93%BE%E6%A8%A1%E5%BC%8F).md)
6. [命令模式command](./Markdown/command(%E5%91%BD%E4%BB%A4%E6%A8%A1%E5%BC%8F).md)
7. [备忘录模式memento](./Markdown/memento(%E5%A4%87%E5%BF%98%E5%BD%95%E6%A8%A1%E5%BC%8F).md)
8. [状态模式state](./Markdown/state(%E7%8A%B6%E6%80%81%E6%A8%A1%E5%BC%8F).md)
9. [访问者模式visitor](./Markdown/visitor(%E8%AE%BF%E9%97%AE%E8%80%85%E6%A8%A1%E5%BC%8F).md)
10. [中介者模式mediator](./Markdown/mediator(%E4%B8%AD%E4%BB%8B%E8%80%85%E6%A8%A1%E5%BC%8F).md)
11. [解释器模式interpreter](./Markdown/interpreter(%E8%A7%A3%E9%87%8A%E5%99%A8%E6%A8%A1%E5%BC%8F).md)

第二部分 设计的六大原则
------------

[](#第二部分-设计的六大原则)

> **开闭原则、里氏代换原则、依赖倒转原则、接口隔离原则、迪米特法则（最少知道原则）、合成复用原则**

1. 开闭原则（Open Close Principle）
    - 开闭原则就是说对扩展开放，对修改关闭。当程序需要进行扩展时，是不能去修改原来的代码的，实现一个热插拔的效果。
    - 其效果是：提供程序的扩展性，维护性。
2. 里氏代换原则（Liskov Substitution Principle）
    - 所有的基类出现的地方，一定可以用其子类替用。
    - `而里氏代换原则` 是对`开闭原则`的一个补充：`开放原则`是规范基类与子类的继承关系，而`里氏代换原则`是规范对实现抽象化的具体步骤。
3. 依赖倒转原则（Dependence Inversion Principle）
    - 它是`开闭原则`的基础
    - 具体内容：真对接口编程，依赖于抽象而不依赖于具体。
    - laravel中也运用这个特性。
4. 接口隔离原则（Interface Segregation Principle）
    - 让接口进行隔离，并且注意使用多个隔离的接口，比使用单个接口要好。
    - 其作用是进行解耦合。
5. 迪米特法则（最少知道原则）（Demeter Principle）
    - 让一个实体尽量少的与另外一个实体进行关联，以保证其模块的相对对立。
6. 合成复用原则（Composite Reuse Principle）
    - 尽量使用合成/聚合的方式，而不是使用继承。

---

参考文章为：

1. [github](https://github.com/yunkaiyueming/php_design_patterns),[web文字](http://www.cnblogs.com/yuqiandoudou/p/4646435.html)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c92d08717347600a268f2c08b9cf00ec5f56b6e098dde3ba66a1228bdaca3a73?d=identicon)[chenjiawen](/maintainers/chenjiawen)

---

Top Contributors

[![melodywen](https://avatars.githubusercontent.com/u/17642785?v=4)](https://github.com/melodywen "melodywen (47 commits)")

### Embed Badge

![Health badge](/badges/mr-jiawen-php-design/health.svg)

```
[![Health](https://phpackages.com/badges/mr-jiawen-php-design/health.svg)](https://phpackages.com/packages/mr-jiawen-php-design)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
