zoukankan      html  css  js  c++  java
  • 策略模式

    <?php
    <?php
    interface math{
        public function calc($op1,$op2);
    }
    
    class mathadd implements math{
        public function calc($op1,$op2){
            return $op1+$op2;
        }
    }
    class mathsub implements math{
        public function calc($op1,$op2){
            return $op1-$op2;
        }
    }
    class mathmul implements math{
        public function calc($op1,$op2){
            return $op1*$op2;
        }
    }
    class mathdiv implements math{
        public function calc($op1,$op2){
            return $op1/$op2;
        }
    }
    
    class cmath{
        protected $calc = null;
        public function __construct($type){
            $calc = "math".$type;
            $this->calc = new $calc();
        }
        public function calc($op1,$op2){
            return $this->calc->calc($op1,$op2);
        }
    }
    
    $type = $_POST['op'];
    $cmath = new cmath($type);
    echo $cmath->calc($op1, $op2);
    

      

  • 相关阅读:
    PMP CMM
    PM过程的一些典型场景和问题
    PMP的六大管理学定律
    项目经理面试指南
    Sd
    Java 对象池实现
    Java 线程池的实现
    Sd
    Sd
    02.JSP的3个编译指令
  • 原文地址:https://www.cnblogs.com/sunlong88/p/8691472.html
Copyright © 2011-2022 走看看