M
Michael Judge
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.
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?
* Class Questionnaire
* Class Question
* Class Interview
Logically, if the interview's answers are more central to your idea of
validation, it goes in Interview:
class Interview
def validates?(pass in a question)
...
end
end
Alternately, if the question structure is more central to your idea of
validation then it goes in Question:
class Question
def validates?(pass in a hash from interview.answers)
...
end
end
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? 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.
Does most object-oriented code look like this? Is decoupled classes an
exception in actual applications rather than the rule? I'm afraid I
don't get how something like validation in a Question could possibly be
isolated from the Interview data.
(Thanks for your input.)
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.
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?
* Class Questionnaire
* Class Question
* Class Interview
Logically, if the interview's answers are more central to your idea of
validation, it goes in Interview:
class Interview
def validates?(pass in a question)
...
end
end
Alternately, if the question structure is more central to your idea of
validation then it goes in Question:
class Question
def validates?(pass in a hash from interview.answers)
...
end
end
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? 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.
Does most object-oriented code look like this? Is decoupled classes an
exception in actual applications rather than the rule? I'm afraid I
don't get how something like validation in a Question could possibly be
isolated from the Interview data.
(Thanks for your input.)