Dynamic method allocation
Posted: Thu Jul 19, 2007 12:33 am
I have been researching extends and factory methods but I don't think they do exactly what I'm looking for.
If I have a class foo..
And class bar..
That is nice, but I'm assuming that if I create an instance of foo, the bar_function() method won't exist, and if I create an instance of bar, I'm getting an instance of bar that has methods inherited from the foo class.
The way I need it to work is for me to create an instance of foo, then somehow add methods from bar to the foo instance.
Is this possible? If not I can create a workaround. I'm just looking for the best solution.
If I have a class foo..
Code: Select all
class foo
{
public function foo_function()
{
}
}
Code: Select all
class bar extends foo
{
public function bar_function()
{
}
}
The way I need it to work is for me to create an instance of foo, then somehow add methods from bar to the foo instance.
Is this possible? If not I can create a workaround. I'm just looking for the best solution.