I have an entity class called Post. Post’s parent is based on an abstract class called AbstractPost. AbstractPost has a variable “author” who’s setter’s signature is defined in an interface called PostInterface.
I am in a situtation where I need to override the author’s setters, but don’t want to modify the parents (ofcourse).
These are the parent classes:
class Post extends AbstractPost
abstract class AbstractPost implements PostInterface
interface PostInterface
I have the following classes:
class MyPost extends MyAbstractPost
abstract class MyAbstractPost extends AbstractPost implements MyPostInterface
interface MyPostInterface extends PostInterface
However, I get the error:
Fatal error: Declaration of MyAbstractPost::setAuthor() must be
compatible with that of PostInterface::setAuthor()
I’ve read that children inherit the “implements” part (what is the right lingo here?) of the parent class, so I gues I want to know how to override that. Or am I not extending/implementing in the right way?
Thanks!
The answer is no.
Overloading the method signature defeats the purpose of having an interface.