Lets say I have a typical factory pattern in PHP code:
abstract class Model
{
function m()
{
}
}
class model_A
{
function a()
{
}
}
class model_B
{
function b()
{
}
}
function modelFactory($name)
{
$className = 'model_' . $name;
$object = new $className();
// ... do some magic stuff ...
return $object;
}
I know about the @var and @return phpdoc tags, but is there any magic way so after typing this:
$x = modelFactory('A');
Eclipse will know $x is an instance of model_A?
Can I define somewhere a fixed vector of strings like this:
"modelFactory('A')" => "new model_A()"
"modelFactory('B')" => "new model_B()"
For Eclipse to replace in memory before processing with code completion.
a()
andb()
tom()
and have themodel_A
andmodel_B
extend theModel
class. In that way there would not be necessary to for outside users to know the difference betweenmodel_A
andmodel_B
– Undertake/** @param model_A $x */
right before instantiating $x. Works perfectly for me, but not sure if Eclipse does this. – Voelker