Next: , Previous: , Up: Creating classes  

6.4.2 Documenting the class

The next step is to associate a description with the class. You do this by sending a message to the new class:

   Account comment:
   'I represent a place to deposit and withdraw money'

A description is associated with every Smalltalk class, and it’s considered good form to add a description to each new class you define. To get the description for a given class:

   Account comment

And your string is printed back to you. Try this with class Integer, too:

   Integer comment

However, there is another way to define classes. This still translates to sending objects, but looks more like a traditional programming language or scripting language:

Object subclass: Account [
    | balance |
        'I represent a place to deposit and withdraw money'>

This has created a class. If we want to access it again, for example to modify the comment, we can do so like this:

Account extend [
        'I represent a place to withdraw money that has been deposited'>

This instructs Smalltalk to pick an existing class, rather than trying to create a subclass.