[Edu-sig] Explaining Classes and Objects
Kirby Urner
urnerk at qwest.net
Mon Jun 13 22:40:15 CEST 2005
> You might try: "These names don't just exist in some primordial soup.
> There has to be a place they get stored. There is a bit of "magic":
> import __main__
> a = 24
> print a, __main__.a
> __main__.a = 365
> print a, __main__.a
>
> And even:
>
> print a, __main__.a, __main__.__main__.a
>
After which I might go:
>>> dir(__main__)
['__builtins__', '__doc__', '__main__', '__name__', 'a']
>>> dir(__builtins__)
That'd connect back to Laura's focus on exception handling -- clearly the
Error related content in __builtins__ is significant.
>>> type(ArithmeticError)
<type 'classobj'>
>>> dir(ArithmeticError)
['__doc__', '__getitem__', '__init__', '__module__', '__str__']
>>> ArithmeticError.__module__
'exceptions'
>>> EnvironmentError.__module__
'exceptions'
>>> import exceptions
>>> dir(exceptions)
> Now everything is dot notation, with some of the "thing." stuff assumed.
> Eventually you'll have to say locacal variables don't really work like
> that, but they are close.
>
universe.milkyway.sun.earth.hawaii.maui is another way to introduce
dot-notation. It's about progressively zooming in, or out, through a
succession of progressively more, or less, encompassing domains.
This gets us back to the root class/object metaphor, which allows us to
appreciate the ordinary interaction of any two objects as involving
encapsulation, polymorphism and message-passing i.e. the original SmallTalk
paradigm.
Kirby
>
> --Scott David Daniels
> Scott.Daniels at Acm.Org
>
More information about the Edu-sig
mailing list