Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!nntp.sei.cmu.edu!news.psc.edu!hudson.lm.com!godot.cc.duq.edu!news.duke.edu!agate!howland.reston.ans.net!ix.netcom.com!netcom.com!pencin
From: pencin@netcom.com (Russell Pencin)
Subject: Re: 'new' method for Object?
Message-ID: <42oq59$cks_001@netcom.com>
Summary: An Analogy of Classes
Keywords: Class MetaClass Behavior
Sender: pencin@netcom6.netcom.com
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
X-Newsreader: News Xpress Version 1.0 Beta #4
References: <42ms5m$fjr@bronze.coil.com>
Date: Fri, 8 Sep 1995 07:08:25 GMT
Lines: 62

In article <42ms5m$fjr@bronze.coil.com>, rskoss@coil.com (R. S. Koss) wrote:
>I'm in the process of teaching myself Smalltalk (VSW) and I'm confused on 
>applying 'new' to a class that hasn't defined 'new'.
>
>I wrote a class BankAccount as a subclass of Object. 
>
>BankAccount new
>
>produces "a BankAccount".
>
>I didn't write new for my class and I don't see a new method in the class 
>methods of Object either, so how does it work?
>
>Bob
>
Bob, you are not the first!
I have seen a few "answers" to your question, but IMHO they miss the point.

Rather than try to explain the "M-word" let me make an analogy that I hope 
will help, then offer a tool that should help you explore the system.

My favorite example is automobiles ( in fact, Ford Taurus').  Let's assume you 
want a Ford Taurus to drive around in.  Well, you have to call the Ford Taurus 
FACTORY to have one built.  This is analogous to sending the new message to 
the Class.  The main point here is that FACTORIES have behavior that is 
different from the instances they create.  You could tell your Taurus to 
accelerate, turn, stop - however these messages would be relatively 
meaningless to the Taurus FACTORY (Class).  You could tell the FACTORY to 
build a new Taurus (new) or ask it the default engine size, or the default 
tire type, etc., again these would be relatively meaningless to the individual 
Taurus.
The concept of FACTORY was first introduced by Brad Cox, and serves well to 
describe the behavior of Classes.  To extend the analogy, all FACTORIES 
intrinsically know how to create instances that they describe (hold the 
template for). This behavior comes from Class->ClassDescription->Behavior.  
This behavior comes from the above hierarchy which for some unknown reason PPS 
decided not to let you look at from the standard browser.  If you spawn the 
hierarchy from the class side you still get the instance hierarchy, pity - 
because for learning you really want to see what Classes provide so as not to 
reinvent the obvious.

There is a tool, originally written by Stephen Pope, stolen and rewritten by 
myself, that allows you to see a flat sorted list of all the methods inherited 
all the way up to Object.  This tool works on BOTH the Class and the Instance 
side.  The System Browser is a DYNOMITE development tool, but a ROTTEN 
learning tool.  I recommend that you go to the ParcPlace Web site 
(www.parcplace.com) or gopher to parcbench@parcplace.com and retrieve the 
"Protocol Browser" in the PIUC folder.  This is a stand alone browser that 
integrates into the standard browser, and will allow you to explore the 
capabilities of objects much more quickly than the system browser.

If this discussion helped and you have other "newbie" questions, don't 
hesitate to e-mail me, this is what I do for a living - training new 
programmers to get the most out of the system with simple analogies and tools.
The second suggestion is obtain the book "The Art and Science of Smalltalk", 
one of the best introductions to the language and its concepts I've come 
across (IMHO).


Russell Pencin
The Smalltalk Brewery, Inc.
pencin@netcom.com
