From 934c7bff78d7847d371c19070074e159cbdf4f8e Mon Sep 17 00:00:00 2001 From: zyimm Date: Tue, 5 Sep 2023 17:12:24 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=BA=E8=AE=BE=E8=AE=A1=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F-=E5=B7=A5=E5=8E=82=E6=A8=A1=E5=BC=8F=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _posts/编程/设计模式/行为模式/factory-method.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/_posts/编程/设计模式/行为模式/factory-method.md b/_posts/编程/设计模式/行为模式/factory-method.md index a2c2f19..6fa4559 100644 --- a/_posts/编程/设计模式/行为模式/factory-method.md +++ b/_posts/编程/设计模式/行为模式/factory-method.md @@ -24,6 +24,7 @@ tags: 设计模式 **😼1.定义cache工厂类(父类)和依赖类** ```php +// config 配置类 用于缓存实例化依赖配置数据 class Config { private string $host; //连接host @@ -79,29 +80,34 @@ class Config } } -``` +// 工厂类 -**😸2.编写各个类型cache子类** - -```php class Cache { protected Config $config; public function __construct(Config $config) { + //通过构造注入Config依赖 $this->config = $config; } public static create(string $cache) { - return new $cache($this->config); + //创建实例 + return new $cache($this->config); } } +``` + +**😸2.编写各个类型cache子类** + +```php + class Redis extends Cache {