zoukankan      html  css  js  c++  java
  • 方法工厂模式

    方法工厂模式

    <?php
    interface LogInterface
    {
        public function log();
    }
    //mysql报错日志
    class MysqlLog implements LogInterface
    {
        public function log()
        {
            // TODO: Implement log() method.
        }
    }
    //Redis报错日志
    class RedisLog implements LogInterface
    {
        public function log()
        {
            // TODO: Implement log() method.
        }
    }
    //用户操作错误日志
    class UserLog implements LogInterface
    {
        public function log()
        {
            // TODO: Implement log() method.
        }
    }
    //代码错诶日志
    class ErrorLog implements LogInterface
    {
        public function log()
        {
            // TODO: Implement log() method.
        }
    }
    
    interface LogFactory
    {
        public function make();
    }
    
    class MysqlLogFactory implements LogFactory
    {
        public function make()
        {
            return new MysqlLog();
        }
    }
    class RedisLogFactory implements LogFactory
    {
        public function make()
        {
            return new RedisLog();
        }
    }
    class UserLogFactory implements LogFactory
    {
        public function make()
        {
            return new UserLog();
        }
    }
    
    class ErrorLogFactory implements LogFactory
    {
        public function make()
        {
            return new ErrorLog();
        }
    }
    
    class Product
    {
        protected $Log;
    
        public function __construct()
        {
            $this->Log = array(
                (new MysqlLogFactory())->make(),
                (new RedisLogFactory())->make(),
                (new UserLogFactory())->make(),
                (new ErrorLogFactory())->make()
            );
        }
    
        public function getLog()
        {
            return $this->Log;
        }
    }
    
    
    
    $product = new Product();
    var_dump($product->getLog());
     
  • 相关阅读:
    git submodule的使用
    Git 工具
    Simple Rtmp Server的安装与简单使用
    Java 获取当前系统的操作系统类型
    OA系统 权限管理的设计流程
    基于角色访问控制的OA系统的设计与实现
    Neo4j:Index索引
    Neo4j Cypher查询语言详解
    win10命令行kill进程
    用BlazeMeter录制JMeter测试脚本
  • 原文地址:https://www.cnblogs.com/clubs/p/15169203.html
Copyright © 2011-2022 走看看