www.delorie.com/gnu/docs/smalltalk/gst_59.html   search  
Buy GNU books!

GNU Smalltalk User's Guide

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.1 Creating a new class

Guess how you create a new class? This should be getting monotonous by now--by sending a message to an object. The way we create our first "custom" class is by sending the following message:

   Object subclass: #Account
       instanceVariableNames: 'balance'
       classVariableNames: ''
       poolDictionaries: ''
       category: nil !

Quite a mouthful, isn't it? Most people end up customizing their editor to pop this up at a push of a button. But conceptually, it isn't really that bad. The Smalltalk variable Object is bound to the grand-daddy of all classes on the system. What we're doing here is telling the Object class that we want to add to it a subclass known as Account. The other parts of the message can be ignored, but instanceVariableNames: 'balance' tells it that each object in this subclass will have a hidden variable named balance. (23)

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003