note 73380 deleted from language.oop5.interfaces by gwynne
| From: | gwynne@php.net | Date: | Mon, 18 Jun 2007 18:17:40 +0000 |
| Subject: | note 73380 deleted from language.oop5.interfaces by gwynne | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127586@lists.php.net to get a copy of this message | ||
Note Submitter: Chris
----
albert:
Of course that doesn't work; it would violate the Liskov substitution principle. Namely: If
Cmyqueue is-a Iqueue, then I must be able to do with an Cmyqueue anything I can do with an Iqueue.
If I can call enqueue() on Iqueue passing any Object, I must be able to do the same with Cmyqueue.
Restricting Cmyqueue::enqueue() to accept only a subclass of Object would break this.
That's why generics (in languages supporting them) don't work like this: a
List<String> cannot be "properly" converted to a List<Object>, because you can
add Objects to a List<Object> but a List<String> should never contain Objects that are
not Strings.