Firstly, this is just an Object Oriented Programming question and does not apply to any Language in particular.
This is quite embarassing for me. This incident happened @ work and I was too shy to clarify this with my colleagues as it would indicate a poor understanding of Object Oriented Programming on my part. So here is the incident :
There is a class A which implements interface I. This interface has a method M. Class A has defined the body or rather implementation of this method.
Now I have a tool with which I can find out which other class or program uses, or in other words calls Class A -> method M.When I used this tool, it did not return any results; An indication which I took as no class is calling method M.
When I shared my observations with a senior colleague, he simply went to the interface I -> method M, and used the tool on this. It returned quite a few results. He told me that these are the classes or methods which call method M and asked me to proceed.
This result is obviously a list of those classes which implement interface I.
But what I didn’t understand is that how is this the set of classes or methods which call Class A -> method M. Since I had confidently told my colleague that no class calls method M, after he showed me the result list, I was too embarassed to ask him how is that the result that I am looking for.
Any idea what my colleague is hinting at?
Regards,
Mithun
The whole idea behind having interfaces for the classes is so that the interfaces will be used to pass the instances. This is to provide loose coupling.
Now, since you do not actually pass the class around but the interface specific to that class,
eg :
instead of
so when you are trying to call a method within
ISomeClass / SomeClasscalledmyMethodinsomeMethod, it is actuallyHence, all usages of
myMethodrefer back toISomeClassand not really toSomeClassEdit: Maybe its just me, but I always believe that when you dont understand something, it is better to open your mouth to ask a question and be mistaken for a fool than to keep it shut and prove yourself to be one!