Hi dominic
When you send the message foo to aA (instance of A)
aA foo
The message is looked up in the class of aA => A foo can be implemented in any superclass of A as Object for example.
Then the method argument receiver is bound to the actual receiver aA in our case.
Now for your question
Foo class>>newFooWithBar: initialBar
| newFoo |
newFoo := Foo new.
newFoo setBar: initialBar.
^ newFoo
the receiver of foo is a CLASS, the semantics of new is: "return an instance of the receiver"
so #new can be implemented in any the superclass of the class FOO ***class*** (ultimately Behavior) (because we send a message to the object that represent the class FOO so we look in its class)
So new is found Then the method argument receiver is bound to the actual receiver Foo in our case. and new returns an instance of Foo.
By the way I suggest you to read the chapter of one my forthcoming book http://scgwiki.iam.unibe.ch:8080/StephaneDucasseWiki/5
On Sunday, May 18, 2003, at 01:58 AM, Dominic Fox wrote:
- Is the best way to make what in C++ or Java you'd call
"constructors" to write class methods that create, initialize and then return an instance, e.g.
newFooWithBar: initialBar
| newFoo |
newFoo := Foo new; setBar: initialBar. ^ newFoo
or is there a more concise way?
OK, I've got this one already. ^ super new init. Had me puzzled for a while (why would I want to return a new instance of the *superclass*?) until I figured out what the superclass was the superclass *of*...
Dominic