Posted by staufferjames
on July 15, 2013 at 1:39 PM PDT
What are the cost vs. benefits of creating interfaces and how should they be balanced?
What are the cost vs. benefits of creating interfaces and how should they be balanced? I am only considering cases where interfaces are optional and aren’t needed.
- Simplify interaction: Easier to see how to use a List than an ArrayList
- Make testing easier because replacement implementations can be used
- Can make future changes easier
- Harder to understand what the code is doing
- When you need to look at the implementing class, it can take a lot of work to find it.
According to SOLID , "one should “Depend upon Abstractions. Do not depend upon concretions.” "
The citation says: “, as much as is feasible, the principle should be followed. The reason is simple, concrete things change alot, abstract things change much less frequently. Morevoer, abstractions are “hinge points”, they represent the places where the design can bend or be extended, without themselves being modified (OCP).”
I don’t see that all or even most concrete things change a lot (at least in their public interface). If the public interface needs to change then doesn’t that mean that the interface class probably would need to change also?
How would that work with a Swing program? Would all GUI elements need to be passed in as interfaces?