Re: How do I handle covariant parameters and not fall foul of LSP.
| From: | David Harkness | Date: | Tue, 14 Feb 2017 20:31:53 +0000 |
| Subject: | Re: How do I handle covariant parameters and not fall foul of LSP. | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-325966@lists.php.net to get a copy of this message | ||
On Tue, Feb 14, 2017 at 2:20 AM, Richard Quadling <rquadling@gmail.com>
wrote:
> If the process method is doing storage related things I don't think is a
> good idea to move it to the Entity hierarchy.
>
I totally agree. I was just showing a way to avoid violating LSP.
On Tue, Feb 14, 2017 at 2:20 AM, Richard Quadling <rquadling@gmail.com>
wrote:
> I still can't see why an extended BaseEntity is still not a BaseEntity,
> just a more specialised variant.
>
Because you're changing the contract in PersonEntity::processEntity() from
taking any BaseEntity to accepting only PersonEntity, you cannot substitute
any BaseEntity for it.
If anyone has some good examples (real world ideally) where LSP is sane AND
> includes inheritance (they seem to be where the conflict lies) then I may
> be able to learn why I'm doing it wrong.
>
A typical example is multiple cache backend implementations: CacheFile and
CacheMemcache. Swapping between the two requires no changes other than the
initial setup. The user of the cache shouldn't know or care which it has.
Cheers!
David