1. <?php 
  2. /**  
  3.  * @意图:工厂方法模型,定义一个用于创建对象的接口,让子类决定实例化哪一个类。Factory Method使一个类的实例化延迟到其子类
  4.  * @适用性:
  5.  * 1、当一个类不知道它所必须创建的对象的类的时候
  6.  * 2、当一个类希望由它的子类来指定它所创建的对象的时候
  7.  * 3、当类创建对象的职责委托给多个帮助子类中的某一个,并且你希望将那一个帮助子类是代理者这一信息局部化的时候
  8.  * @author:王康
  9.  * @copyright:http://blog.csdn.net/wkjs
  10. */  
  11. ?> 
  12. <?php
  13. /**  
  14.  * @name:
  15.  * @uses:Page
  16.  * @version:1.0.0
  17.  * @author:王康
  18.  * @copyright:http://blog.csdn.net/wkjs
  19. */  
  20. abstract class Page {
  21. }
  22. ?>
  23. <?php
  24. /**  
  25.  * @name:
  26.  * @uses:SkillsPage
  27.  * @version:1.0.0
  28.  * @author:王康
  29.  * @copyright:http://blog.csdn.net/wkjs
  30. */  
  31. class SkillsPage extends Page {
  32. }
  33. ?>
  34. <?php
  35. /**  
  36.  * @name:
  37.  * @uses:EducationPage
  38.  * @version:1.0.0
  39.  * @author:王康
  40.  * @copyright:http://blog.csdn.net/wkjs
  41. */  
  42. class EducationPage extends Page {
  43. }
  44. ?>
  45. <?php
  46. /**  
  47.  * @name:
  48.  * @uses:ExperiencePage
  49.  * @version:1.0.0
  50.  * @author:王康
  51.  * @copyright:http://blog.csdn.net/wkjs
  52. */  
  53. class ExperiencePage extends Page {
  54. }
  55. ?>
  56. <?php
  57. /**  
  58.  * @name:
  59.  * @uses:IntroductionPage
  60.  * @version:1.0.0
  61.  * @author:王康
  62.  * @copyright:http://blog.csdn.net/wkjs
  63. */  
  64. class IntroductionPage extends Page {
  65. }
  66. ?>
  67. <?php
  68. /**  
  69.  * @name:
  70.  * @uses:ResultsPage
  71.  * @version:1.0.0
  72.  * @author:王康
  73.  * @copyright:http://blog.csdn.net/wkjs
  74. */  
  75. class ResultsPage extends Page {
  76. }
  77. ?>
  78. <?php
  79. /**  
  80.  * @name:
  81.  * @uses:ConclusionPage
  82.  * @version:1.0.0
  83.  * @author:王康
  84.  * @copyright:http://blog.csdn.net/wkjs
  85. */  
  86. class ConclusionPage extends Page {
  87. }
  88. ?>
  89. <?php
  90. /**  
  91.  * @name:
  92.  * @uses:SummaryPage
  93.  * @version:1.0.0
  94.  * @author:王康
  95.  * @copyright:http://blog.csdn.net/wkjs
  96. */  
  97. class SummaryPage extends Page {
  98. }
  99. ?>
  100. <?php
  101. /**  
  102.  * @name:
  103.  * @uses:BibliographyPage
  104.  * @version:1.0.0
  105.  * @author:王康
  106.  * @copyright:http://blog.csdn.net/wkjs
  107. */  
  108. class BibliographyPage extends Page {
  109. }
  110. ?>
  111. <?php
  112. /**  
  113.  * @name:
  114.  * @uses:Document
  115.  * @version:1.0.0
  116.  * @author:王康
  117.  * @copyright:http://blog.csdn.net/wkjs
  118. */  
  119. abstract class Document {
  120.     
  121.     /**
  122.      * This is variable page description
  123.      *
  124.      * @var mixed 
  125.      *
  126.      */
  127.     public $page=array();
  128.     
  129.     /**
  130.      * This is method __construct
  131.      *
  132.      * @return mixed This is the return value description
  133.      *
  134.      */
  135.     public function __construct() {
  136.         $this->Document();
  137.     }
  138.     
  139.     /**
  140.      * This is method Document
  141.      *
  142.      * @return mixed This is the return value description
  143.      *
  144.      */
  145.     public function Document() {
  146.         $this->CreatePages();
  147.     }
  148.     
  149.     /**
  150.      * This is method CreatePages
  151.      *
  152.      * @return mixed This is the return value description
  153.      *
  154.      */
  155.     public abstract function CreatePages();
  156. }
  157. ?>
  158. <?php
  159. /**  
  160.  * @name:
  161.  * @uses:Resume
  162.  * @version:1.0.0
  163.  * @author:王康
  164.  * @copyright:http://blog.csdn.net/wkjs
  165. */  
  166. class Resume extends Document {
  167.     
  168.     /**
  169.      * This is method CreatePages
  170.      *
  171.      * @return mixed This is the return value description
  172.      *
  173.      */
  174.     public function CreatePages() {
  175.         $this->page[]=new SkillsPage();
  176.         $this->page[]=new EducationPage();
  177.         $this->page[]=new ExperiencePage();
  178.     }
  179. }
  180. ?>
  181. <?php
  182. /**  
  183.  * @name:
  184.  * @uses:Report
  185.  * @version:1.0.0
  186.  * @author:王康
  187.  * @copyright:http://blog.csdn.net/wkjs
  188. */  
  189. class Report extends Document {
  190.     
  191.     /**
  192.      * This is method CreatePages
  193.      *
  194.      * @return mixed This is the return value description
  195.      *
  196.      */
  197.     public function CreatePages() {
  198.         $this->page[]=new IntroductionPage();
  199.         $this->page[]=new ResultsPage();
  200.         $this->page[]=new SummaryPage();
  201.         $this->page[]=new BibliographyPage();
  202.     }
  203. }
  204. ?>
  205. <?php
  206. /**  
  207.  * @name:
  208.  * @uses:调用说明
  209.  * @version:1.0.0
  210.  * @author:王康
  211.  * @copyright:http://blog.csdn.net/wkjs
  212. */  
  213. $documents=array(new Resume(),new Report());
  214. foreach($documents as $value) {
  215.     foreach((array)$value->page as $cls) {
  216.         echo get_class($cls).'<br />';
  217.     }
  218.     echo '<hr />';
  219. }
  220. ?>
posted on 2008-10-22 02:48  wkjs  阅读(211)  评论(0编辑  收藏  举报