I'm looking at this form an Objective-C background so be gentle. The experiment looks like this:
Object1 has an instance variable named delegate.
Object1 receives a message and the proceeds to check if delegate implements a specific protocol (whose name is known beforehand), if it does, then it checks if the message is among the protocol's implemented methods. It then makes a decision on how to interact with the delegate and so on.
In Objective-C one has to define clear Protocols, usually stored in different files, and conforming to a protocol is checked by the compiler. In Pharo I can't seem to find how to check for this kind of information even though the Browser has a whole column dedicated to protocols, and beside grouping methods they seem to do very little.
Here are some few alternatives that could help you with this:
anObject class selectors
anObject class allSelectors
anObject class canUnderstand: #putTheSelectorHere
anObject respondsTo: #methodSelectorHere
MessageNotUnderstood
mechanism:In 1 and 2 above you can use the returned collections to check whether they include a certain selector you are interested in. Features 3, 4 and 5 have a more dynamic nature. For example, you can refine the
#doesNotUnderstand:
method in your class as follows:This way, if your object receives a message that it does not understand, it will first receive the
#doesNotUnderstand:
message (without you having to do anything for this to happen) and here you could decide (e.g., by using the#respondsTo:
message) whether to delegate it or not. If not, you can just relay on the default behavior (super doesNotUnderstand:
) which would signal deMessageNotUnderstood
exception.Of course, there is a 6th option, which would be for the sender of the message to handle the MNU exception, but I don't think this is what you are looking for here.
There is the proxies work in Ghost/Marea and the original Smalltalk wrappers to the rescue I'm not sure the proxies have been updated for the latest Pharo version. Latest ghost version seems to be here