|
Re: Name spaces in Dolphin...
panu wrote:
> There is a simple workaround for class-namespaces that
> works in *every* Smalltalk (and in Java too). Before
> complicating things further by adding explicit class-
> namespace support to a language, consider using this
> design pattern:
An even more extreme point along the same design axis also obviates the need
for namespaces.
I recently (just for fun/interest in how it'd turn out) chose to implement a
small toy project in a style where all responsibility for creating objects (and
hence all references to classes) were the responsibility of a single
system-wide object. That object (which was named after the system) also had
the responsibility for providing access to the several "important" objects in
the system. I quite liked the way the code turned out, and may repeat the
experiment sometime. I've always felt that the actual class of an object
should be seen as a private matter -- an implementation detail only -- and in
this case I was able to design the system so that it fitted properly with that
idea. (At least from the outside, I did cheat on a few occasions in the
internals of the system).
Here's a couple of examples of how it looks from the outside:
"Music" is the name of the system, and the global that is the sole external
entrypoint.
"get/make a note of G#"
Music G sharp.
"--> Music G sharp"
"add a minor third to a note"
Music G + Music minorThird
"--> Music B flat"
"answer the notes in a C major scale"
Music C major notes
"--> #(Music C Music D Music E Music F Music G Music A Music B)"
And so on. (BTW I know nothing of music theory, so the above may be wrong --
the system was just an attempt to learn a bit of the basics of the theory by
turning it into code). All classnames (except 'Music'), and much of the class
structure, are hidden from the external code that uses the library. Internally
the pattern is much the same; e.g, the implementation of
MusicAbstractNote>>major which was used in the previous example:
major
"answer a major key with ourself as tonic"
^ self music major withTonic: self.
-- chris
|