Is it code smell to make an abstract child class implement a method, which overrides a parent method, whose only purpose is to call another abstract method? I want to make sure that anyone who implements my abstract class is aware that there needs to be special handling to override the functionality of a parent method. And making the parent method call my abstract method seems to be the best way to do that.
However it also feels redundant, someone could just override the parent method directly.
Here is some example code. It is totally contrived because I don't want to reveal what kind of code I'm actually working on. Please pay less attention to the example code because it may not be the best.
I'm wondering if this is ok? Or is it a symptom of code smell and I should re-work the code somehow.
<?php
abstract class Mammal {
public function move() {
// ... a bunch of complicated logic implementing common walk logic
}
}
abstract class NonWalkingMammal extends Mammal {
// Override the parent method to implement special handling defined by the abstract getMove() method.
public function move() {
return $this->getMove();
}
// NonWalkingMammals must implement logic for their movement
abstract protected function getMove();
}
class Bat extends NonWalkingMammal {
protected function getMove()
{
// ... flying logic
}
}
class Whale extends NonWalkingMammal {
protected function getMove()
{
// ... swimming logic
}
}