I have two abstract classes in an inheritance chain, within what will eventually be a generic library:
abstract class Foo {
public function baz() {
echo 'Foo::baz()';
}
// other methods here
}
abstract class Bar extends Foo {
public function baz() {
echo 'Bar::baz()';
}
}
These two classes are meant to be extended by developers, and my problem is that I'd like to make it so that neither implementation of the baz() method can be overridden (as they contain strict RFC-compliant code). Making Bar::baz() final is no problem; however, if I make Foo::baz() final, then Bar itself obviously can't override it either.
PHP 5.4's traits would likely offer a practical solution, but I can't drop support for PHP < 5.4 over this. My last resort is to just leave it as-is and use documentation to warn developers not to override this method, but I'd like to find something more concrete, if possible.
Is there any other design I can use to enforce that both methods shouldn't be overridden, while simultaneously keeping the code DRY (e.g. not removing the inheritance and duplicating all the code)?
Barneeds to overridebaz, thenFoo::bazdoesn't really contain "strict RFC-compliant code." And if there's one class that needs to override it to make it really compliant, how do you know that nobody else will have yet another class that needs to override it to make it really compliant for something else?baz()methods and make them bothfinal).finalmethods, but I wanted to ping the community for alternatives I overlooked, if any.