Message/Method

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Message/Method

Blake-5
        I'm not sure whether to ask this here or on the main list, but I thought  
I'd start here.

In a traditional 3GL with objects bolted on, methods are subroutines with  
a hidden "self" parameter, so if I write (using, oh, Object Pascal):

MyObject.MyMethod;

I know that MyObject is of a class that has a method (or an ancestor with  
a method) called MyMethod.

        I have read things on Smalltalk that suggest to me that:

myObject myMethod.

the selector "myMethod" does not necessarily map one-to-one with a method  
named "myMethod".

        But I haven't been able to figure out how that could be, or under what  
situation it would be useful.

        Any thoughts?

        ===Blake===
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Message/Method

Bert Freudenberg
On Dec 5, 2006, at 11:52 , Blake wrote:

> I'm not sure whether to ask this here or on the main list, but I  
> thought I'd start here.
>
> In a traditional 3GL with objects bolted on, methods are  
> subroutines with a hidden "self" parameter, so if I write (using,  
> oh, Object Pascal):
>
> MyObject.MyMethod;
>
> I know that MyObject is of a class that has a method (or an  
> ancestor with a method) called MyMethod.
>
> I have read things on Smalltalk that suggest to me that:
>
> myObject myMethod.
>
> the selector "myMethod" does not necessarily map one-to-one with a  
> method named "myMethod".
>
> But I haven't been able to figure out how that could be, or under  
> what situation it would be useful.

The difference is that you can send any message to any object, and  
the object's class can decide how to handle that method. By default,  
the class looks into the dictionary of all defined methods and  
invokes the matching method. But it can also decide to handle *any*  
message, regardless of which methods are actually defined. This lets  
you implement, for example, generic object wrappers that log any  
message sent to an object. Or, forward the message over the network  
to another image. Or, which is the normal case, raise an exception  
that this message was not understood.

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Message/Method

Bert Freudenberg

On Dec 5, 2006, at 12:00 , Bert Freudenberg wrote:

> On Dec 5, 2006, at 11:52 , Blake wrote:
>
>> I'm not sure whether to ask this here or on the main list, but I  
>> thought I'd start here.
>>
>> In a traditional 3GL with objects bolted on, methods are  
>> subroutines with a hidden "self" parameter, so if I write (using,  
>> oh, Object Pascal):
>>
>> MyObject.MyMethod;
>>
>> I know that MyObject is of a class that has a method (or an  
>> ancestor with a method) called MyMethod.
>>
>> I have read things on Smalltalk that suggest to me that:
>>
>> myObject myMethod.
>>
>> the selector "myMethod" does not necessarily map one-to-one with a  
>> method named "myMethod".
>>
>> But I haven't been able to figure out how that could be, or under  
>> what situation it would be useful.
>
> The difference is that you can send any message to any object, and  
> the object's class can decide how to handle that method.

I meant to write "... to handle that *message*" of course ;)

> By default, the class looks into the dictionary of all defined  
> methods and invokes the matching method. But it can also decide to  
> handle *any* message, regardless of which methods are actually  
> defined. This lets you implement, for example, generic object  
> wrappers that log any message sent to an object. Or, forward the  
> message over the network to another image. Or, which is the normal  
> case, raise an exception that this message was not understood.
>
> - Bert -
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Message/Method

Blake-5
In reply to this post by Bert Freudenberg
On Tue, 05 Dec 2006 12:00:40 -0800, Bert Freudenberg  
<[hidden email]> wrote:

> The difference is that you can send any message to any object, and the  
> object's class can decide how to handle that method. By default, the  
> class looks into the dictionary of all defined methods and invokes the  
> matching method. But it can also decide to handle *any* message,  
> regardless of which methods are actually defined. This lets you  
> implement, for example, generic object wrappers that log any message  
> sent to an object. Or, forward the message over the network to another  
> image. Or, which is the normal case, raise an exception that this  
> message was not understood.

Aha. You can do that with Object Pascal, too, though not so directly.

Thanks.
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners