What If..... Strong Types

Michael Gilfix mgilfix at eecs.tufts.edu
Sun Jun 16 12:31:23 EDT 2002


On Sun, Jun 16 @ 04:08, Don Garrett wrote:
>    Primarily, what if classes always had rigidly defined interfaces. I mean 
> that public members had to be declared to exist, and that methods couldn't be 
> modified on an instance. Private members could exist but would be really private.

  Do you think you really gain anything by public/private
interfaces? What's wrong with the way python approaches
intefaces? Information hiding and interface exposure are done by
contract: e.g. When I say: instance.__var, __var is considered private
and cannot be gotten at by conventional means, but can still be gotten
at if a programmer is determined. And sometimes, it's *nice* to be
able to do so. There are times when you have a set, 'rigid' inteface,
which you know won't change, such as in a well-defined API, and you're
using a class which almost does what you need but not exactly. Then
this lack of public/private becomes a blessing because if you
understand how the underlying class works, you can get at information
without breaking the semantics of the class. But you still have the
advantage of private members - no one can use those members without
being very explicit and going out of their way to do so. In fact, I
often believe that the C++ 'protected' can often be what people really
want...  If you're really into a rigid interface, then make use of the
'__'. Same beneift, less hinderance.

                        -- Mike

-- 
Michael Gilfix
mgilfix at eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html





More information about the Python-list mailing list