Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!europa.chnt.gtegsc.com!howland.reston.ans.net!math.ohio-state.edu!news.cyberstore.ca!vanbc.wimsey.com!fonorola!news!dbuck
From: dbuck@infoweb.magi.com (David Buck)
Subject: Re: Smalltalk terminology - Object, Class, and Instance
Sender: news@magi.com
Message-ID: <DAuz7L.5Gs@magi.com>
Date: Wed, 28 Jun 1995 01:09:21 GMT
References: <3shvfp$l9k@portal.gmu.edu> <DAsuBL.9Ir@mv.mv.com>
Nntp-Posting-Host: infoweb.magi.com
Organization: Magi Data Consulting
Lines: 50

In article <DAsuBL.9Ir@mv.mv.com>, L. M. Rappaport <rapp@lmr.mv.com> wrote:
>mtran2@osf1.gmu.edu (My-Phuong L Tran) wrote:
>>I am very confused by the meanings of these three important terms in ST.
>>To give an example of the difficulties I would like to quote from a
>>typical book on Smalltalk, 'An Introduction to Object-Oriented
>>Programming and Smalltalk', by Lewis J.Pinson and Richard S.Wiener,
>>which by the way is *fantastic*.

How about this for an explanation:

An object is something that contains data and operations that act on that 
data.  For example, a bank account containing a balance, an owner name, 
and an account number would be an object.  Operations include things like 
deposit: and withdraw:.

The class corresponds (roughly) to the kind of object.  To use the above 
example, my bank account and your bank account are both objects.  The 
class is BankAccount.  The term 'object' is synonymous with 'instance of 
a class'.  In this case, my bank account is an instance of the class 
BankAccount.

The class determines what information is contained in the instances (in 
other words, the all instances of the class will have the same kind of 
information but with different values).  The class also determines how 
the instances behave - what messages do they understand.

So, my bank account and your bank account are both instances of the class 
BankAccount.  As such, they both contain a balance, an owner name, and an 
account number but they have different values.  Both bank accounts can do 
withdraw: and deposit: since they are both instances of BankAccount.

Classes (like BankAccount) can have subclasses (like SavingsAccount).  
Instances of the subclasses can have more information stored in them than 
instances of the superclass and they may have new or different behaviors 
defined for them.  When not explicitly re-defined, instances of 
the subclasses can do everything that instances of the superclass could 
do.  So, you may decide that on a SavingsAccount, a withdrawal might 
incur a service charge.

The confusing bit is that in Smalltalk, the class is itself an object.  
Hence, it is an instance of some class (that's called a metaclass).  You 
don't really have to worry about these details at this stage.  It gets 
pretty hairy when you trace it all through.

Does this help at all?

David Buck
dbuck@magi.com
The Object People

