Re: horizontal reuse: traits vs. grafts

From: Date: Thu, 25 Mar 2010 15:00:25 +0000
Subject: Re: horizontal reuse: traits vs. grafts
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-47606@lists.php.net to get a copy of this message
On 25.03.2010, at 14:48, David Soria Parra wrote:

> Just as a general idea (which is certainly something after traits are implemented once)
> 
> Scala offers stackable traits so that you can mixin traits during object creation.
> An example:
> 
> trait Philosophical {
>    public function think () {
>        echo "Cogito ergo sum";
>    }
> } 
> 
> trait Drink {
>    public function drink () {
>        echo "gluck gluck"
>    }
> }
> 
> $obj = new Person();
> 
> $obj->think(); // will fail
> 
> $obj = new Person() with Philosophical;
> $obj->think(); // works
> 
> $obj = new Person() with Philsophical, Drink;
> $obj->drink(); // works
> $obj->think(); // works
> 
> This approach is taken in scala and works pretty fine there for composing classes
> during runtime and should be douable in PHP too. For sure aliasing is not
> possible in this example.
> 
> But as said just a general idea that I might try to work on once traits are comittet.
> 
> Stefan what do you think about "stackable traits" ?


Woha .. that code really scares me.

regards,
Lukas Kahwe Smith
mls@pooteeweet.org





Thread (21 messages)

« previous php.internals (#47606) next »