Classes as Packages (was: Harvesting infrastructure)

tblanchard at mac.com tblanchard at mac.com
Tue Nov 19 07:50:45 UTC 2002


On Monday, November 18, 2002, at 10:53  PM, Anthony Hannan wrote:

> Sorry Todd, I forgot to address your question before.  Here it is:
>
> tblanchard at mac.com wrote:
>> I think inheritance is way overworked as a composition mechanism.
>> There are other more interesting techniques that have been
>> underutilized including delegation and forwarding and method
>> categories.  I do more ObjectiveC than ST and ObjC has method
>> categories - loadable groups of methods that you can add to a class
>> anytime you like without recompiling.  This lets you add behavior to a
>> class without really changing its type.  (Inheritance generally
>> indicates type - which is different from protocol).
>> Your MI approach sounds something like categories - but adds fuzzy
>> typing ideas too I think.
>> Maybe I don't entirely understand your proposal - but suppose a 
>> package
>> requires the addition of a bit of behavior to Object - will Object now
>> derive from something else too?
>
> Yes, you would add the behavior required by the package in a new
> behavior and make Object a subclass of it.

Why is it a subclass?  These "classes" you are describing don't seem 
have much in common with the classes we have now.  For one thing, 
you've mentioned that there is no state.  But Smalltalk classes 
generally do have state.  So are you implying we change classes in 
Squeak to not have state, or are you saying these mixins you are 
proposing aren't really classes like we have now but something else?

Personally I'd rather have method bundles (categories) that add to a 
class without requiring mucking about with the class hierarchy.

As for adding protocol to Object - its done fairly often - simple 
example is to have a project Foo that manages FooElements - I'm quite 
likely to add a method category FooExtensions to Object and put an 
isFooElement method (returning false) that I override in FooElement to 
return true.




More information about the Squeak-dev mailing list