Inheriting Array and slice() behaviour

W

William Morgan

Excerpts from Devin Mullins's mail of 8 Jul 2005 (EDT):
Wrong. The LSP says that /objects/ of a subtype have to support the same
interface. That is, it specifically ignores the constructor. That's how
Java gets away with not inheriting the constructor.

Thank you (and Adam Jenkins) for clarifying this.

So the LSP doesn't say anything about constructors (and rightly so IMO).
So we're back to where we started: subtypes of Array can have
non-trivial constructors and #initialize can't be called automatically
for them.

Currently:
- invalid (non-initialized) objects returned by Array#slice
- Array#slice inconsistent with other Array methods

If Array#slice calls #initialize:
- arbitrary restruction on subtype constructor signatures
- Array#slice still inconsistent with other Array methods

If you make Array#slice return an Array:
- no constructor or invalid object issues
- Array methods consistent

I suspect this is a one-line patch to rb_ary_subseq.

Ok, I'm about to spend the weekend with no electricity or running water
thanks to you guys (just kidding!) so no more of this boring thread from
me until Sunday. :)
 
D

Devin Mullins

William said:
Thank you (and Adam Jenkins) for clarifying this.

So the LSP doesn't say anything about constructors (and rightly so IMO).
So we're back to where we started: subtypes of Array can have
non-trivial constructors and #initialize can't be called automatically
for them.

<summary follows>
Good summary.

BTW, I started reading some of the LSP thread on the c2 wiki that
somebody else linked to. Pretty interesting. It seems several of them
want to draw a distinction between subclass and subtype -- they find
that there are times they want to subclassing but not follow LSP. I
think they're using a language that doesn't have mixins, Forwardable,
etc. so subclassing is the only way for them to share code between
classes. :)
Ok, I'm about to spend the weekend with no electricity or running water
thanks to you guys (just kidding!) so no more of this boring thread from
me until Sunday. :)
Good luck! I should probably quit posting on this thread, too, before
people start killfiltering me...

Devin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,491
Latest member
mohitk

Latest Threads

Top