![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a simple interface with two methods, MethodA, and MethodB. I also have a class with implements the interface. The class provides a full implementation for MethodA but for special reasons, provides only a stub for MethodB, with no code in it. The code that uses the interface needs to be able to tell if MethodB has actually been implemented by the class. For example: (pseudocode) If MethodBHasCode Then MyInterface.MethodB() Endif My questions: 1. Is there any attribute I can apply to the stubbed method in the class so that I can see if it has actually been implemented? |
|
2. Should I just call MethodB as if it had been implemented? Is there any performance issues with calling an empty sub? |
#3
| |||
| |||
|
|
2. Should I just call MethodB as if it had been implemented? Is there any performance issues with calling an empty sub? It's unlikely to be a bottleneck, certainly - I would only worry about it when you've definitely got a problem. One thing you could do is add a custom attribute which you'd create (eg StubImplementationAttribute) to the stub implementation - then you could look for that. |
#4
| |||
| |||
|
|
One thing you could do is add a custom attribute which you'd create (eg StubImplementationAttribute) to the stub implementation - then you could look for that. ... but that would certainly take more time than just calling the empty method. |
#5
| |||
| |||
|
|
It would take more time if you had to do it every time, yes. You'd want to cache that information - indeed, you might end up putting objects which only had stub implementations into a different collection, etc. It all depends on the situation. |
#6
| |||
| |||
|
|
an empty method to be extremely small - if the compiler doesn't optimize away the call to begin with. I guess if you were going to use a single |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |