zswordsman / design_patterns

PHP设计模式

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP设计模式

代码实现均在Yjc目录,测试代码在App里。

本库是学习PHP设计模式所写的测试代码。核心代码均在Yjc目录里。为了测试方便,其实已经完成了简单的MVC框架的封装。

大家可以按照下面的文档进行测试,然后看代码实现。本人水平有限,欢迎提出修改建议。

设计模式

创建模式

架构模式

行为模式

开始测试

需要有运行环境。使用PHP7的同学可以直接使用下面的方法开启Server,免去Nginx配置PHP环境烦扰。

开启server

php -S 0.0.0.0:8888

浏览器输入:http://localhost:8888

设计模式测试

简单工厂

/SimpleFactoryTest/index

示例:
URL路径:http://localhost:8888/SimpleFactoryTest/index
对应文件:App/SimpleFactoryTest
对应源码:Yjc/SimpleFactory

工厂方法

/FactoryTest/index

抽象工厂

/AbstractFactoryTest/index

单例模式

/SingletonTest/index

注册树模式

/RegisterTest/index

原型模式

/PrototypeTest/index

适配器模式

/AdapterTest/index
AdapterTest/index2

装饰器模式

/DecoratorTest/index

策略模式

/StrategyTest/index

观察者模式

/Observertest/index

迭代器模式

/IteratorTest/index

About

PHP设计模式


Languages

Language:PHP 100.0%