zoukankan      html  css  js  c++  java
  • 设计模式:模板方法模式

    一、模板方法模式

      模板方法模式。定义为:Define the skeleton of an algorithm in an operation,deferring some steps to subclasses.Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.( 定义一个操作中的算法的框架, 而将一些步骤延迟到子类中。 使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。 )

    <?php
        abstract class  Template{
            protected abstract function title();
            protected abstract function body();
    public function show(){ echo "标题:" . $this->title() . PHP_EOL; echo "内容:" . $this->body() . PHP_EOL; } } class php_language extends Template { protected function title(){ return "我是PHP"; } protected function body(){ return "PHP是世界上最好的语言"; } } class html_language extends Template { protected function title(){ return "我是html"; } protected function body(){ return "html/css/js 网页三剑客"; } }
  • 相关阅读:
    使用yield实现一个协成
    串讲-Python基础练习
    Linux练习
    列表生成式
    Jupyter Notebook的快捷键帮助文档
    mysql字段类型
    爬取12306火车票信息
    【Lodop】02 C-Lodop手册阅读上手
    【Lodop】01 Lodop手册阅读上手
    【Redis】06 事务
  • 原文地址:https://www.cnblogs.com/onlycat/p/9164958.html
Copyright © 2011-2022 走看看