Classes

How do you create objects? In some languages you have to build them one at a time, but it's more convenient to have a mechanism that produces them for you. This mechanism is called a class.

You can think of a class as a factory that can produce programming objects. Each factory makes just one kind of object, or product. For example, we could have a BankAccount class, from which we produce bank accounts, a Menu class, from which we produce menus for a user interface, or a Dictionary class, from which we produce objects that behave like real dictionaries. In Smalltalk, heres how you might use a Dictionary dass:

Dictionary new

Left to right. Dictionary receives the message named new. Because Dictionary is a class or factory, it responds to new by creating a brand-new dictionary object. 'What happens to this object from now on is up to you. Being a dictionary, it may have operations like add: that would permit you to add a new entry to it. You could gradually add to it and make it into any kind of dictionary you liked.

Realistically, if we want to continue to use this dictionary object, …