ObjectOriented
20-Sep-95 10:18:35
Sb: #48209-ObjectOriented
Fm: Greg Comeau@Comeau Cmptg 72331,3421
To: Clay Spence 72713,2540
>>…structures, why do you need some enforcement mechanism to control this?
>
>I would guess that it keeps you from having to design and remember rules that
>help you "be careful how you manipulate your data structures." The rules, to
>some extent, are designed for you. You get to design the classes, of course,
>so the rules aren't completely determined by the language.
You are correct on both counts. It does go beyond the freedom of choice re
whether to use it or not though. Most "involved data" (ugh) will be better
off for having used said features. It's not so much that you need the
enforcement, but that you want it. It goes beyond just because of
protection from accident (though that's good too). IMO, it's an intimate
part of the composition process.
>There are also cases in which it gives sensible structure. For example, I've
>written a neural net program in C. There are different kinds of neurons with
>different functions, and different sets of parameters for each kind. It makes
>sense to define a common interface that applies to each neuron type. I defined
>a structure that contains the variables that are common to any neuron type, a
>void pointer that code for each neuron type can initialize as it sees fit, and
>pointers to functions to implement the common functions, like "initialize
>yourself," "evaluate your output," etc. The higher-level code can just call
>the function pointed to in the neuron's structure without having to "know"
>which function to call for the neuron type. The higher-level code is
>simplified quite a lot by this, I think. If I had learned C++ I would hope
>that it would have been simpler.
It is! BTW, this seems like a good design. It of course just so happens
that you've implemented it in C, and using things _implementation details_
like you've explained are the right things to do in C. All this is left to
you though, and with no language support. It would be nice to have been
able to express your design in something that look like that way you
mentally envisioned it.
>I don't see this as an enforcement mechanism, but perhaps I'm wrong.
Oh, it involves it, but it is not as exclusive as the raw feature in a
vacuum implies, so you are right.