日期:2011-12-05 浏览次数:20483 次
解释器: 解释器设计模式用于分析一个实体的关键元素,并且针对每个元素都提供自己的解释或相应的动作。
解释器设计模式最常用于PHP/HTML 模板系统。
- <?php
- class User {
- protected $_username = "";
- public function __construct($username) {
- $this->_username = $username;
- }
- public function getProfilePage() {
- $profile = "<h2>I like Never Again ! </h2>";
- $profile .= "I love all of their songs. My favorite CD: <br />";
- $profile .= "{{myCD.getTitle}}!!";
- return $profile;
- }
- }
- class userCD {
- public function setUser(User $user) {
- $this->_user = $user;
- }
- public function getTitle() {
- $title = "Waste of a Rib"<