From: james_b Date: 2003-09-03T11:20:28+09:00 Subject: Re: OOP flavors - was Re: Python vs. Ruby Hal Fulton wrote: > I've just realized that in the back of my mind, I prefer passing > the "little object" into the "big object" rather than vice versa. > Hmm. A psychological aspect there. > > Much of what Ruby already does bears this out, I think. > > array << item # not item << array > stack.push(item) # not item.push(stack) > queue.add(item) # not item.add(queue) Note, though, that none of these cases require the receiver to know anything about the argument. It doesn't require calling any getter methods or otherwise peering into the received object. I think Holub's point is that one should avoid passing one object to another where the receiving object needs to extract and act on data properly owned by the passed object. For example, imagine a class Sorter that sorts the data held in some object: sorter.sort( myArray ) One could argue that this is perfectly OK, since it's the Sorter that does the sorting, not the array. But that's not terribly convincing. A Polygon might render itself by sending messages to a Window; it wouldn't need to ask Window for its data. But a Window (probably) could not render a Polygon without asking the Polygon for it for its data. (I think the Law of Demeter comes into play here as well ...) > > Junk-food for thought... Tasty, still. James > > Hal > > >