php设计模式 Template (模板模式)

简介:这是php设计模式 Template (模板模式)的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。

class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=338931' scrolling='no'>
1 <?php
2 /**
3 * 模板模式
4 *
5 * 定义一个操作中的算法骨架,而将一些步骤延迟到子类中,使得子类可以不改变一个算法的结构可以定义该算法的某些特定步骤
6 *
7 */
8 abstract class TemplateBase
9 {
10 public function Method1()
11 {
12 echo "abstract Method1<br/>";
13 }
14
15 public function Method2()
16 {
17 echo "abstract Method2<br/>";
18 }
19
20 public function Method3()
21 {
22 echo "abstract Method3<br/>";
23 }
24
25 public function doSomeThing()
26 {
27 $this->Method1();
28 $this->Method2();
29 $this->Method3();
30 }
31 }
32
33 class TemplateObject extends TemplateBase
34 {
35 }
36
37 class TemplateObject1 extends TemplateBase
38 {
39 public function Method3()
40 {
41 echo "TemplateObject1 Method3<br/>";
42 }
43 }
44
45 class TemplateObject2 extends TemplateBase
46 {
47 public function Method2()
48 {
49 echo "TemplateObject2 Method2<br/>";
50 }
51 }
52
53 // 实例化
54 $objTemplate = new TemplateObject();
55 $objTemplate1 = new TemplateObject1();
56 $objTemplate2 = new TemplateObject2();
57
58 $objTemplate->doSomeThing();
59 $objTemplate1->doSomeThing();
60 $objTemplate2->doSomeThing();

爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

http://biancheng.dnbcw.info/php/338931.html pageNo:8
原文地址:https://www.cnblogs.com/ooooo/p/2246201.html