[ENH] Class Extensions

Brent.Pinkney at reuters.com Brent.Pinkney at reuters.com
Thu Jun 28 17:07:39 UTC 2001


Hi,

In an attempt to make more Squeak more modular I have implemented a Extensions class similar to those found in VisualAge. This is my first cut I have the gall to publish.

1. Concept
----------
We can define methods in system categories different to the one in which the class is defined. These methods can then be installed and deinstalled.

2. Architecture
---------------
For now I have made Extension a subclass of ClassDescription to inherit all the methods used by Browser.

ie
ProtoObject
   Object
      Behavior
         ClassDescription
            Class
            Metaclass
            Extension

3. Look and Feel
----------------
New extensions are defined in the Browser as such:

    Smalltalk
        extend: #String
        category: 'Kernel-Numbers'

The extension then appears in the browser as:

    String (extension)

As this point methods can be added and removed as normal. These methods cannot be used until they are installed.

4. Workspace
------------
4.1. The extensions of a class can be found by evaluating:

    String extensions.

4.2 Just as the printString for a class or metaclass class can be evaluated to return the object,
       so the printString for a class can be evaluated to return the printString instance.

   String extensions first ->  String extensionIn: 'Kernel-Numbers'

5. Filein/FileOut
------------------
An extension can be filed in and out as a .st file.
Currently ChangeSets are not supported. Advice would be appreciated.

6. ToDo
-------
6.1. I have not yet decided how to support extension methods for the class side of a class. Advice appreciated.
6.2. Support for ChangeSets is missing.
6.3. Support to refactor existing classes into extensions. Scripts, etc.
6.4. What to do about ImageSegments. Advice appreciated.
6.5. Removing the extension from the image.
6.5. General enhancements.

7. Samples
----------
7.1 The Extensions change set.
7.2 A file out of an extension to String.
    File it in and try to evaluate: 'foo' asNil.
    Now browse category 'Kernel-Numbers'. You will see the exntesion in the class list.
    Select the install menu option.
    Now try 'foo' asNil.
    Voila !


8. Advanced
-----------
For elegance and symmetry with the definition string for an extension, modify

   Preferences>>#printDefinitionInEnvironment to return true.

Now browse classes defined in the environment (Smalltalk). It is time.


9. Comments
-----------
I have always thought that extensions were one of the most useful and elegant features in VisualAge as they encourage terse conversion methods, locality, etc.

Having had the dubious priviledge of evaluating C#, I predict that one day C#/Java/C++ et al. will introduce extensions into the language and claim it as the New Greatest Thing.

eg.

namespace acme.stuff
{
    extension System.string
    {
        public object toNil()
        {
            return nil;
        }
    }
}

To the masses, Java pretended garbage collection was an innovation, Javascript suggested dynamic typing was new; let nail this one please.

PS. I will be back on Monday to reply.

Cheers
Brent

(See attached file: Extensions.46.cs)

(See attached file: String (extension).st)












-----------------------------------------------------------------
        Visit our Internet site at http://www.reuters.com

Any views expressed in this message are those of  the  individual
sender,  except  where  the sender specifically states them to be
the views of Reuters Ltd.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Extensions.46.cs
Type: application/octet-stream
Size: 30525 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20010628/c4f05b19/Extensions.46.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: String (extension).st
Type: application/octet-stream
Size: 270 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20010628/c4f05b19/Stringextension.obj


More information about the Squeak-dev mailing list