I have an abstract PHP class called 'Car'.
abstract class Car
{
// Extending class must define this method
abstract protected function getBrand();
abstract protected function getCars();
// Common methods
public function printBrand() {
print $this->getBrand() . PHP_EOL;
}
public function printUrl() {
print $this->getUrl() . PHP_EOL;
}
}
This abstract class implements a function getCars()
, but this function has basically the same content for each child but with different variables. As there are a couple dozen of children, this method getCars()
gets redundant. Some children may also need to override the getCars()
function.
Should I just copy the getCars()
code to the abstract class and replace the variables with $this->getVar()
? Or is this not good practice? Thanks in advance.
Edit: If this is the way to go, can some specific children override this abstract function?