Consider a class that prints an "outline" table for a particular product line. Say you have several, A, B, C, D. The mechanism of the table generation is the same, but the data is different. I could create a "base" class called OutlineTableGenerator
, and one class per product line each that extend that base class. I can put data getters into individual product classes and let the base class operate on the data. Observe below:
class OutlineTableGenerator
{
protected $vars;
function __construct($vars)
{
$this->vars = $vars;
}
public function getOutlineTable()
{
$data = $this->getOutlineTableData(); //my question is about this line
}
}
and
class OutlineTableGeneratorForProductA extends OutlineTableGenerator
{
function __construct($vars)
{
parent::__construct($vars);
}
protected function getOutlineTableData()
{
return ['data' => $this->vars['stuff']];
}
}
See line $data = $this->getOutlineTableData();
. My problem with this line is that my IDE, nor any other IDE for that matter, will be able to figure out which class & function it will resolve to at run time. I quite frequently use a feature to jump from the line in the code where a function is called, to the actual function declaration. In this case, I using that feature on the line in question will not jump to function declaration. Because there are several of those, and nor IDE nor programming language itself knows which function I want. I think this is bad.
Is there a work-around? Is this a drawback of polymorphism in OO? How do YOU live with it?