Robert Klemme
6/20/2006 9:21:00 PM
Michael Judge wrote:
> Hello,
>
> I'm having trouble with decoupling. I agree that information hiding /
> decoupling is a universally good thing, but in practice I'm having
> trouble actually keeping classes isolated from each other.
Having classes coupled isn't a bad thing in itself. In fact, OO is
mostly about how to distribute responsibilities across several
collaborating classes.
> Say you're programming a survey application. When a respondent submits
> a question, the data needs to be validated. Where does the validation
> method (validates?) go?
It depends on what you mean by "validate". Do you mean test validity of
input? Or checking answers for correctness? Maybe you tell a bot more
about the relationship between questionnaire, interview and question and
we can come up with more suggestions.
> In either case, a bridge is being built between the two objects because
> the method doesn't fit cleanly within one or the other. Isn't that
> obnoxious?
Double dispatch isn't too unusual - just think of the visitor pattern or
CLOS, i.e. Lisps implementation of OO which allows method dispatch based
not only on a single instance as most other OO languages but on several
instances / their types.
> I find myself agonizing over this kind of problem all the
> time. As a consequence, my classes are never reuseable unless they're
> trivial things that aren't worth reusing.
Don't say that. A library built of "trivial" things can be a time
saver, too.
Kind regards
robert