您的位置 首页 php

PHP设计模式之模版模式

模版模式属于行为型模式

概述:定义一个操作的算法骨架,而将一些步骤延迟到子类中,模版方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤

<?php

/**

*模版模式基类

*/

abstract class Template{

public function templateA(){}

public function templateB(){}

public function getTemplate(){

$this->templateA();

$this->templateB();

}

}

<?php

/**

* 子类

*/

class TemplateChild extends Template{

public function templateA(){

echo ‘A’;

}

public function templateB(){

echo ‘B’;

}

}

<?php

/**

*模版方法

*/

public function actionTemplate(){

Yii::import(‘ext.template.*’);

$templateC = new TemplateChild;

$templateC->getTemplate();

}

文章来源:智云一二三科技

文章标题:PHP设计模式之模版模式

文章地址:https://www.zhihuclub.com/150632.shtml

关于作者: 智云科技

热门文章

网站地图