posted 14 years ago
if you code to an interface, then the underlying object can be changed to a different object type, as long as that new type still implements the interface.
Example: we each purchase a class called 'searchTool' from a 3rd party that does some searching. it implements the 'searchList' interface.
You write your code to specifically use the 'searchTool'. You call it's methods directly, access specific parts, and use some of it's pieces in your code.
I write my code to use the 'searchList' interface. I ONLY refer to it by the interface name, only use the interface methods.
a year later, they come up with a 'fastSearchTool' class that implements the 'searchList' interface, and it runs 100 times faster. I don't have to change a single line of my code, and I can drop in the 'fastSearchTool' to gain the benefit.
You, however, have to re-write all your code to now use the new class, if you want to gain the benefits. So while I'm sitting on the beach drinking Maitai cocktails, you are in the office, slogging through your code to make your changes.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors