[squeak-dev] Proper Smalltalk lots of classes

Colin Putney colin at wiresong.com
Fri Dec 31 23:12:07 UTC 2010


On Fri, Dec 31, 2010 at 5:24 PM, Jimmie Houchin <jlhouchin at gmail.com> wrote:

> In the Java implementation there are over 2000 classes. In the protocol
> there are approximately 90 message types and 956 field types.

[snip]

> Am I way off base here? Should I really create the 956 classes necessary to
> for each field in addition to the 90 or so message classes, and then I don't
> know what else I haven't discovered yet. Having 1000+ classes just seems
> unwieldy and naively it just doesn't feel like the Smalltalk way. I could be
> wrong, but I haven't seen such an example to my memory. I don't know enough
> about Java to know if it is good Java form either.

[snip]

I'm not a Java expert, but I can sort of see the rational for having
so many classes in a statically-typed language. You can use the type
system to enforce the correctness of the protocol implementation. With
a class for each type of field, you can declare variables with the
types of fields expected by the protocol, and the compiler will tell
you if you try to do something that doesn't fit the protocol
specification.

In a dynamic language like Smalltalk, though, I'd expect classes that
map to the *structure* of the protocol rather than it's specification.
Perhaps many of those 956 field types are quite similar and can be
modelled by just a handful of classes.

Another thing to look out for is opportunities to model things with
composition instead of inheritance. The Java implementation is
modelling the protocol largely in the type system, and as such it has
to have single objects to which the types can be applied. Since you're
going to be modelling the protocol with objects rather than types
you're free to represent the elements of the protocol with clusters of
objects. (For example, you might have a Field object that only
represents the data in the field, and contains a reference to a
FieldType object that describes the semantics of the field).

BTW, Congratulations on taking on such a big project - good to see it
happening in Smalltalk.

Hope this helps,

Colin



More information about the Squeak-dev mailing list