Reputation: 5203
I am going to develop a COM component for a WIN CE device. Is there any limits on the number of methods that can be added to a COM Interface(Component)?
Upvotes: 1
Views: 174
Reputation: 5262
One of the benefits of an interface is that multiple classes can reuse your interface. This would allow programs to use the same methods on different classes without caring what they are.
One of the intentions of COM is to hide the implementation of the class you are accessing. The user isn't suppose to know, given an interface, what is exactly behind that interface.
Imagine you have a chair, now imagine you have a bike. Both can use the interface ISeat. The user can sit on either object without knowing which the user sat on. Now bike can use the interface IPedal, and chair wouldn't use that interface. Now chair doesn't have to have all the methods that bike implements (like PedalForward).
If chair had to implement those methods because you only have one interface, you'd have to do something with those methods. You could have the method do nothing, but that would be useless to the user, and possibly dangerous, as the user could be trying to pedal a chair away from a car so he doesn't get hit by the car. Or, you could throw an exception. Which would be odd, as the user would wonder why the object can't pedal forward.
So, if you have too many methods in one interface, presence of god-class aside, you're not taking advantage of COM in the way it was meant to be used.
Upvotes: 4
Reputation: 101456
No.
But if you have to add a lot of methods to a single class, there's a very good chance your design is broken.
Also, keep in mind that once you publish a COM interface, your never "supposed" to change it.
Upvotes: 3