Total members 11894 |It is currently Sun Nov 24, 2024 7:43 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Code:
<?
  
class Name {
    
private $firstName;
    
private $lastName;

    function
__construct($lastName_in, $firstName_in) {
      
$this->firstName = $firstName_in;
      
$this->lastName  = $lastName_in;
    }

    function
getFirstName() {
        return
$this->firstName;
    }

    function
getLastName() {
        return
$this->lastName;
    }

    function
getFirstNameAndLastName() {
      return
$this->getLastName() . ' by ' . $this->getFirstName();
    }
  }


  class
LastNameDecorator {
  
    
protected $name;
  
public $lastName;
  
    
public function __construct(Name $name_in) {
    
$this->name = $name_in;
      
$this->resetLastName();
    }
  
  function
resetLastName() {
    
$this->lastName = $this->name->getLastName();
  }

    function
showLastName() {
    return
$this->lastName;
  }

  }
  
  
  class
LastNameExclaimDecorator extends LastNameDecorator {
  
    
private $btd;

    
public function __construct(LastNameDecorator $btd_in) {
       
$this->btd = $btd_in;
    }

    function
exclaimLastName() {
       
$this->btd->lastName = "!" . $this->btd->lastName . "!";
  }
  }

  class
LastNameStarDecorator extends LastNameDecorator {
  
private $btd;
    
public function __construct(LastNameDecorator $btd_in) {
    
$this->btd = $btd_in;
    }

    function
starLastName() {
    
$this->btd->lastName = Str_replace(" ","*",$this->btd->lastName);
  }
  }
  
  
  
  
$patternName = new Name("A","B");
        
  
$decorator = new LastNameDecorator($patternName);
  
$starDecorator = new LastNameStarDecorator($decorator);
  
$exclaimDecorator = new LastNameExclaimDecorator($decorator);
  
  echo
$decorator->showLastName();
  
  
$exclaimDecorator->exclaimLastName();
  
$exclaimDecorator->exclaimLastName();
  echo
$decorator->showLastName();
  
  
$starDecorator->starLastName();
  echo
$decorator->showLastName();
  
  echo
$decorator->resetLastName();
  echo
$decorator->showLastName();      
?>




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Design Patterns Decorator
 Design Patterns Composite in php     -  
 J2EE Design Patterns     -  
 Regular Expressions and Patterns     -  
 What are H1, H2 & so on in web design?     -  
 GUI Design     -  
 DAO design pattern     -  
 about dao design pattern     -  
 Design of OS in java     -  
 How to design these JSP pages?     -  
 Web content & Website Design     -  



Topic Tags

PHP OOP
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com