Those of you who’ve read [ruby-talk:70422] ( [OO interface design]
Pass-by reference VS encapsulation ?) know I’m designing a lightweight
personal addressbook editor (and using it as a testcase to practice my
design/pattern skills).
From the very start I’ve been feeling uneasy about my setup: I have an
Addressbook class that stores Contact instances which store attributes
(name, birthdate, phoneNr, …). I chose this setup because I wanted (at
the lowest level) an interface that could be used by all clients and
would guarantee data integrity and consistence (the Addressbook prevents
the addition of a contact if an similarly named contact already exists
and the Contact class has writers that throw exceptions when the data
does not comply with the requirements).
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.
Looking forward to your responses.
– Simon
···
–
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton