[ANN] MiniTraits (on SqueakMap)

Stephen Pair spair at acm.org
Fri Dec 13 21:41:44 UTC 2002


To support some work I'm doing on Kats, I needed some simple traits like
capabilities.  I implemented this package to hold me over until a more
robust implementation appears.  I've put it up on SqueakMap.  

>From the package description:
----
Name:		MiniTraits
Summary:	A small implementation of Traits
Author:		Stephen Pair <spair at acm.org>
Maintainer:	Stephen Pair <spair at acm.org>
Registrant:	spair at acm.org

Categories: 
	Maturity level/Beta - Useable but still not stable, probably has
bugs.
	Licenses/SqueakL - The license of Squeak from Apple. The only
license we allow for inclusion in base Squeak.
	Squeak versions/Squeak3.4 - 
	Squeak versions/Squeak3.2.1 - The maintenance branch of 3.2, go
there for future 3.2 fixes.
	Squeak versions/Squeak3.2 - Released 16 Jul 2002.

Current version: 1.0
Homepage:	http://spair.swiki.net/35
Download:	http://people.advantive.com/~spair/squeak/MiniTraits.sar

Description:
MiniTraits is a small implementation of Traits functionality.  It
enables you to create a set of behavior and state that can be reused by
other classes in a way that is orthogonal to the normal class hierarchy.

Here's how MiniTraits work:

To create a new trait, simply subclass MtTrait and add whatever methods
(instance and/or class side) or instance variables that you like. Then,
you can add the behavior of your new trait to other classes in the
system with the following expression:

SomeClass addTrait: MyTrait

You can remove a trait using #removeTrait: or #removeTrait:ifAbsent:.
You can ask a class what traits it is using with the message #traits.
All methods inherited from a trait will be placed in method categories
that are prefixed with the trait name. This helps distinguish methods
inherited from a trait from normal methods.

When you add or remove methods in a trait class, any other classes that
are currently using the trait will be affected. If a method is added to
the trait, it will be added to the classes using it (but only if that
class doesn't already implement that selector). Similarly if you remove
a method from a trait, any classes using that trait will also have that
selector removed (but only if the selector was added by the trait).

Removing or redefining a selector that is inherited from a trait will
cause a confirmation dialog to pop up. You will be asked whether you
would like to make the change in the trait, or just for the class
itself. When removing a selector that is overriding (shadowing) a
selector of the same name in an inherited trait, the inherited version
of the method will be installed in the class.

The net effect is very similar to inheritance.

Several extensive SUnit tests are provided to ensure the proper
functioning of this package.




More information about the Squeak-dev mailing list