Next: , Up: More subclassing  


6.9.1 The Existing Class Hierarchy

To discuss where a new class might go, it is helpful to have a map of the current classes. The following is the basic class hierarchy of GNU Smalltalk. Indentation means that the line inherits from the earlier line with one less level of indentation.35.

  Object
    Behavior
      ClassDescription
        Class
        Metaclass
    BlockClosure
    Boolean
      False
      True
    Browser
    CFunctionDescriptor
    CObject
      CAggregate
        CArray
        CPtr
      CCompound
        CStruct
        CUnion
      CScalar
        CChar
        CDouble
        CFloat
        CInt
        CLong
        CShort
        CSmalltalk
        CString
        CUChar
          CByte
            CBoolean
        CUInt
        CULong
        CUShort
    Collection
      Bag
      MappedCollection
      SequenceableCollection
        ArrayedCollection
          Array
          ByteArray
          WordArray
          LargeArrayedCollection
            LargeArray
            LargeByteArray
            LargeWordArray
          CompiledCode
            CompiledMethod
            CompiledBlock
          Interval
          CharacterArray
            String
              Symbol
        LinkedList
          Semaphore
        OrderedCollection
          RunArray
          SortedCollection
      HashedCollection
        Dictionary
          IdentityDictionary
            MethodDictionary
          RootNamespace
            Namespace
            SystemDictionary
        Set
          IdentitySet
    ContextPart
      BlockContext
      MethodContext
    CType
      CArrayCType
      CPtrCType
      CScalarCType
    Delay
    DLD
    DumperProxy
      AlternativeObjectProxy
        NullProxy
          VersionableObjectProxy
        PluggableProxy
    File
      Directory
    FileSegment
    Link
      Process
      SymLink
    Magnitude
      Association
      Character
      Date
      LargeArraySubpart
      Number
        Float
        Fraction
        Integer
          LargeInteger
            LargeNegativeInteger
            LargePositiveInteger
              LargeZeroInteger
          SmallInteger
      Time
    Memory
    Message
      DirectedMessage
    MethodInfo
    NullProxy
    PackageLoader
    Point
    ProcessorScheduler
    Rectangle
    SharedQueue
    Signal
      Exception
        Error
          Halt
            ArithmeticError
              ZeroDivide
            MessageNotUnderstood
          UserBreak
        Notification
          Warning
    Stream
      ObjectDumper
      PositionableStream
        ReadStream
        WriteStream
          ReadWriteStream
            ByteStream
              FileStream
      Random
      TextCollector
      TokenStream
    TrappableEvent
      CoreException
      ExceptionCollection
    UndefinedObject
    ValueAdaptor
      NullValueHolder
      PluggableAdaptor
        DelayedAdaptor
      ValueHolder

While initially a daunting list, you should take the time to hunt down the classes we’ve examined in this tutorial so far. Notice, for instance, how an Array is a subclass below the SequenceableCollection class. This makes sense; you can walk an Array from one end to the other. By contrast, notice how this is not true for Sets: it doesn’t make sense to walk a Set from one end to the other.

A little puzzling is the relationship of a Bag to a Set, since a Bag is actually a Set supporting multiple occurrences of its elements. The answer lies in the purpose of both a Set and a Bag. Both hold an unordered collection of objects; but a Bag needs to be optimized for the case when an object has possibly thousands of occurrences, while a Set is optimized for checking object uniqueness. That’s why Set being a subclass or Bag, or the other way round, would be a source of problems in the actual implementation of the class. Currently a Bag holds a Dictionary associating each object to each count; it would be feasible however to have Bag as a subclass of HashedCollection and a sibling of Set.

Look at the treatment of numbers—starting with the class Magnitude. While numbers can indeed be ordered by less than, greater than, and so forth, so can a number of other objects. Each subclass of Magnitude is such an object. So we can compare characters with other characters, dates with other dates, and times with other times, as well as numbers with numbers.

Finally, you will have probably noted some pretty strange classes, representing language entities that you might have never thought of as objects themselves: Namespace, Class and even CompiledMethod. They are the base of Smalltalk’s “reflection” mechanism which will be discussed later, in The truth on metaclasses.


Footnotes

(35)

This listing is courtesy of the printHierarchy method supplied by GNU Smalltalk author Steve Byrne. It’s in the kernel/Browser.st file.


Next: , Up: More subclassing