Re: Decorator with public methods

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Friday 26 December 2008 11:06:07 pm Nathan Nobbe wrote:

> to summarize, using your example above, i would most liely add doThings()
> to Baz, or create another decoration interface for doThings() if you plan
> on using the Bar implementation of doThings() in many places,
>
> interface G {
>   function doThings();
> }
>
> class Bar extends Decorator implements G {
>   function doThings() {
>     // concreate implementation
>   }
> }
>
> class Baz implements F, G {
>   // recycle Bar::doThings()
>   public function doThings() {
>     return $this->foo->doThings();
>   }
>   public function doOtherThings() {}
> }
>
> i appologize if this response is long winded, but im a big fan of the
> decorator, and ive actually got some pretty slick code in production in the
> photobucket code that uses the decorator pattern :D  it took about 2 months
> to code, and i leraned a lot about some of the practical aspects of
> decroration, specifically within the realm of php.  i know i repeated a few
> things there, but i felt it neccessary to better explain myself.
>
> -nathan

Thanks, Nathan.  Unfortunately, what you describe is impossible.  It requires 
me to know all the possible decorators ahead of time and implement the 
interface for each in each decorator, at which point I've gotten no benefit at 
all over just putting everything in the original base class in the first place.  
That defeats the purpose of decorators if I can't come up with a new one a 
month from now and not have to modify any of the existing code.

-- 
Larry Garfield
larry@xxxxxxxxxxxxxxxx

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux