Re: Generic decorators and type hinting

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

 



> I have a possibly-evil idea that gets around type-hinting by
> dynamically declaring decorator classes as children of the real
> classes that need to be timed. You end up with as many "decorators" as
> you have classes that need to be timed, but if this is for dev/QA
> purposes only, that might not be a problem.

You don't even need to do that; it'd generate way too much redundant
code.  Instead, just use interfaces.  The only real downside is that
all the classes you want to decorate would need to implement them and
that would cause a wee bit of ugliness in the code/class declaration.
But if you are fine with that, it's a perfect solution, particularly
since you can type hint interfaces.

interface iDecorator {}

class Thing implements iDecorator {}

class Timer
{
  public static function time( iDecorator $obj ) {}
}

$obj = new Thing();
Timer::time( $obj ); // $obj becomes a Timer obj with $obj inside it
$obj->thingMethod(); // Timer passes call to Timer->obj

thnx,
Christoph

-- 
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