[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Inheriting Array and slice() behaviour

Devin Mullins

7/6/2005 8:31:00 PM

> This is a lisp-like language, so expressions are basically array of atoms
> and expressions. When I do a slice() this is to get a subset of the list,
> but a subset is not an expression itself.
>
> Expression is-a Array, but Expression.slice is just an Array

Pragmatically, I'd suggest that you use the has-a relationship, as mentioned. Make the Array of atoms an instance variable of Expression, and give the Array an attr_reader. If you want to provide convenience methods that access the methods of the Array, that's fine, too. Modify the instance methods of Expression to act on the instance variable instead of on self.

Is there any reason that this would be bad?

Pedantically, it doesn't quite sound like Expression is-a Array. It doesn't satisfy Array's general contract. (See http://en.wikipedia.org/wiki/Liskov_substitution... .)

Devin




1 Answer

Sylvain Joyeux

7/6/2005 8:45:00 PM

0

> Pragmatically, I'd suggest that you use the has-a relationship, as
> [...]
I'm not trying to talk about pragmatism (the program already works,
thanks :D), but about concepts :p

> Is there any reason that this would be bad?
No, I was just investigating another way of doing it

> Pedantically, it doesn't quite sound like Expression is-a Array. It
> doesn't satisfy Array's general contract. (See
> http://en.wikipedia.org/wiki/Liskov_substitution... .)
Can you be more specific ? I think it would have if slice returned an
Array)

Sylvain

--
Sylvain Joyeux