|
Re: Name spaces in Dolphin...
Blair McGlashan wrote:
> I'm afraid there is a downside, and it is incompatibility. There is no one
> standard namespace system, in fact they are all different, and often not
> just in the detail. ...
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:
1. Create all your classes with a suffix.
For example I could create a new class
called 'TransformerPANU'. It is unlikely
that anyone would come up with the same
name in their designs.
2. Create a method named #Transformer in your
class(es) or superclass as:
Transformer
^TransformerPANU
3. In your code, instead of accessing the global
'TransformerPANU' directly, call:
self Transformer.
This has the added benefit (over plain namespaces)
that you now *encapsulate* the information of which
actual object will be returned by #Transformer!
Using a method-call in this manner leads to more
cohesive, flexible, reusable code than accessing
a global directly (in several places). Remember
the Trick-of-63: Globals are BAD.
The downside is that 'self Transformer' is slightly
longer than plain 'Transformer', but that's the
price you pay for better encapsulation, and for
keeping the language & code simple and compatible
with other dialects.
-Panu Viljamaa
|