0

I am using smalltalk - i need to check if objectA has all the messages(methods) that objectB has .

i need to write my own code, how could it be done ?

2Big2BeSmall
  • 1,348
  • 3
  • 20
  • 40
  • 4
    Please, ask for something more specific and, most of all, show here what you have done to find this problem. Otherwise, it just seems that you are repeating here something that was asked to you in the context of a course. The question alone, without more context, seems artificial. – Carlos E. Ferro Jun 22 '15 at 18:56
  • 1
    what isnt clear in my question ? – 2Big2BeSmall Jun 22 '15 at 19:32
  • @Francy The question makes sense. But you could for example explain if your problem is, how to find out all the messages one object understands, or if you have trouble comparing the results. – MartinW Jun 22 '15 at 21:28
  • 1
    @Francy Also try to get the terminology right. An _object_ might _understand a message_ based on the _methods it's class and it's superclasses implement_. – MartinW Jun 22 '15 at 21:35

2 Answers2

2

You could for example ask the class of an object which selectors it's instances understand:

objectA class allSelectors

Then you could ask different objects and compare the results.

MartinW
  • 4,966
  • 2
  • 24
  • 60
2

The solution might be

objectA class allSelectors includesAll: objectB class allSelectors
Norbert Hartl
  • 10,481
  • 5
  • 36
  • 46
  • Note that using just #selectors is not enough, because you miss the methods defined in superclass/es. You should use #allSelectors, like @MartinW said – Carlos E. Ferro Jun 23 '15 at 14:41
  • True. I thought that the question is not clear about that and was focused on classes where the question is ambiguous. But on an object base I think you are right – Norbert Hartl Jun 24 '15 at 09:22