Re: OO Design induces an existential crisis



> >One piece of advice - try your hand at coding Kata. Cf. the recent
> >thread about the Coding Dojo. I can give you a couple that exercise OO
> >skills.
>
> I'm all ears.

Here's one I stole from this newsgroup in the first place. I've found it
makes a good exercise in OO thinking for people who have trouble getting
it (I've used it with a group of COBOL programmers that I've been
training):
http://endrardy.notlong.com

Don't stop at figuring out the classes, actually go and code a simple
version of the system without a UI or database. Start by figuring out
what the test cases are. That's important - the test cases will
correspond to the relevant events that may change the state of the
system.

> I know that some sort of discipline as to "which classes know what"
> is necessary or at least highly desirable, but I don't have any
> basis for designing this discipline, nor enough tricks up my sleeve

"Which classes know what" starts out as an analysis problem. In the
restaurant example, I've found that good questions to ask are: *Who* is
interested in whatever the system does ? *When* (under what
circumstances) does that person interact with the system ? *What*
characterizes the desired outcomes of the interaction ?

You can capture your (provisional) answers to these questions as a test
case. Your system should be able to pass this test case. The next
question is, what has to be known about the various entities in the
problem statement in order to solve this test case ? That's not yet a
complete answer to "which classes know what", but it will help you
generate possibilites. The next step is to critically review the
resulting design. Each class should "know" only the bits of information
that are absolutely critical to it, and collaborate with other classes
for the rest; each bit of information should reside in one class only;
and so on.

The neat thing about the Restaurant Kata is that it's very small, a
handful of classes at most. You can afford to do it over and over. Do
that, and trust to repetition (and reflection on what's different from
one version to the next) to finally get the hang of it.

Laurent
.