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());
     
  • 相关阅读:
    签字文件的保存逻辑
    POJ-1273 Drainage Ditches
    POJ-2513 Colored Sticks
    HDU-1251 统计难题
    POJ-1300 Door Man
    POJ-3159 Candies
    POJ-3169 Layout
    POJ-2983 Is the Information Reliable?
    POJ-1716 Integer Intervals
    HDU-3666 THE MATRIX PROBLEM
  • 原文地址:https://www.cnblogs.com/clubs/p/15169203.html
Copyright © 2011-2022 走看看