From: dblack@... Date: 2003-05-14T06:26:19+09:00 Subject: Re: [OO design] Objects VS Datastructures Hi -- On Wed, 14 May 2003, Simon Vandemoortele wrote: > The problem I see in this setup is that my 'Objects' are very passive; > they are not much more than datastructures with an attitude. Their whole > interface consists of setters and getters. I've been wondering if this > is still OO ? Shouldn't I be sending 'messages' instead of "taking some > 'Object', pulling out some information to shove it somewhere else" ? > > What are your thoughts on this matter ? Am I doing procedural > programming in a OO language or is this an unavoidable consequence of > the addressbook problem I am trying to solve ? > > Corollary: It has also occurred to me that Contact#setName(aString) > where Contact checks if the name satisfies certain > conditions might not be the best setup since a 'name' is not > string; it is much narrower than that (in my > implementation). Maybe I'd better create a Name class that > represents a 'name' object and enforces it's integrity. > Doing that for all Contact's attributes would reduce it's > responsibilities to the point where it would barely differ > from a Hash, thus exacerbating the question above. Rather than Contact#setName (or even Contact#set_name :-) you'd probably be better off leveraging Ruby's idiomatic set/get mechanism: Contact#name # getter Contact#name= # setter (which you can do easily with the attr_* family of shortcuts, or by hand if you need more complexity). Technically this is no more or less of a "message"-based way than what you're doing now (since all method calls in Ruby are based on the message-sending model), but it's a better fit with the language and might start to give you a stronger sense of the Contact objects (and others) as more than data structures. David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav