Closed devanych closed 2 years ago
I think that in this case extension would be the right solution
Why not an interface?
Why not an interface?
Because in this case, when expanding, children do not redefine the behavior of the parent in any way, as it should be with proper expansion. And all classes will be implementations of the same IdentityInterface
.
If you create the interface GuestIdentityInterface
and inherit it from the IdentityInterface
, then there is a problem. In IdentityInterface
here is such a method:
public function getId(): ?string;
in GuestIdentityInterface
we need such a method:
public function getId(): null;
Firstly, the PHP syntax will not allow this to be done, and secondly, making an interface with a single method that should always return null
is generally some kind of crazy idea :)
But NOT the final class:
class GuestIdentity implements IdentityInterface
{
final public function getId(): ?string
{
return null;
}
}
Allows you to completely solve the issue without problems.
@devanych i don't agree with you, but as always, it's too late.
It's never too late :)
Makes the
GuestIdentity
NOT final, but thegetId()
method final. It could be expanded if necessary. I think that in this case extension would be the right solution.