At a high level, my knowledge of Interfaces is such that:
- They declare methods but do not implement them
- Any class that implements an Interface must implement all of its declared methods
To me, this immediately exposes two major problems:
Because any implementing class must implement all of its methods, this in effect means an Interface can not be changed once it has been used. Adding or removing methods in the Interface would mean altering every class that uses it. The answer is probably exactly that; that they should never be changed, but how can we guarantee that our design is that stable?
Suppose the classes that implement the Interface actually use the same logic in their implementations. This is code repetition, making it difficult to maintain. Isn't that the point of base classes and inheritance?
I got to this thinking because I thought I had a good grasp of it. I thought an Interface as a 'bolt on' or 'plug in' to the Class, giving it some extra functionality, whereby the functionality isn't tied to that type of class, for example an Interface might define methods to calculate surface area, but lots of things have a surface area, not just 'shape' or 'building', so it seems reasonable to create a 'bolt on' (Interface) for calculating surface area, yet it's probable that every implementation of that Interface will be the same, so where is the benefit? Is this a fair comment? I'm sure they provide great benefit, I just don't see it yet.