zoukankan      html  css  js  c++  java
  • php多态

    对php多态的理解:

    /**
     * 定义接口
     */
    interface Shape{
        public function draw();    
    }
    /**
     * 三角形
     */
    class Triangle implements Shape{
        public function draw(){
            echo "This is Triangle";    
        }
    }
    /**
     * 矩形
     */
    class Rectangle implements Shape{
        public function draw(){
            echo "This is Rectangle";    
        }
    }
    class TestPoly{
        public function drawNow($shap){
            $shap->draw();
        }
    }
    $test = new TestPoly();
    $test->drawNow(new Triangle);
    echo '<br />';
    $test->drawNow(new Rectangle);
    If the copyright belongs to the longfei, please indicate the source!!!
  • 相关阅读:
    跨域上传文件
    算法
    websocket
    Bottle
    爬虫一
    RabbitMQ
    git&github快速入门
    centos6安装SaltStack
    ajax
    Django之Model操作
  • 原文地址:https://www.cnblogs.com/longfeiPHP/p/5394225.html
Copyright © 2011-2022 走看看