vendredi 27 mai 2016

is this a decorator pattern (PHP)?

I was watching a Lynda.com PHP Design Patterns tutorial when the tutor presented this solution to a challenge:

index.php:

include_once 'decorator.php';

$object = new Decorator();
$object->sentence = "This is a sample sentence that we're going to   manipulate in the Decorator.";

// This should output: this is a sample sentence that we're going to     manipulate in the decorator.
echo $object->lower();

// This should output: THIS IS A SAMPLE SENTENCE THAT WE'RE GOING TO     MANIPULATE IN THE DECORATOR.
echo $object->uppercase();

decorator.php:

class Decorator
{
        public $sentence = '';

    public function lower()
{
    return strtolower($this->sentence);
}

public function uppercase()
{
    return strtoupper($this->sentence);
}

Why is this a decorator pattern? All I see is the instantiation of an object and accessing two of the objects methods.

Aucun commentaire:

Enregistrer un commentaire