Web lists-archives.com

Re: [PHP] How do I handle covariant parameters and not fall foul of LSP.

On Sun, Feb 19, 2017 at 1:56 AM, Tony Marston <TonyMarston@xxxxxxxxxxx>

> "Richard Quadling"  wrote in message news:CAKUjMCXEXqy=VB8Jjjg8XKdU
> sc5NsqQTeZcs54+V5e4GH1RYYw@xxxxxxxxxxxxxx...
>> <snip>
>> That's fine for concrete classes, but abstract classes which cannot be
>> instantiated, therefore cannot be swapped, cannot fall foul of LSP. It is
>> the abstract part that, in my mind, should be making the difference.
> That is correct. LSP does not come into play when you inherit from an
> abstract class, only when you inherit from one concrete class to create a
> different concrete class. The author of LSP should have made this clear.

I believe LSP should apply to all class hierarchies. If you have a List
interface and supply an AbstractList partial implementation, all
classes—concrete or not—that implement List or extend AbstractList should
be substitutable for all others. LinkedList, ArrayList, SubList, etc.

What Richard is encountering is a breakdown due to PHP not having support
for generics. PersonRepository is a subclass of Entity and breaks LSP
because we'd rather have Repository<Person>. So he's not really violating
LSP in spirit, only in practice because PHP.