Program to an interface
One of the good design principles is to program to an interface. What does programming to an interface mean? An easy way to explain this is to think of the domain model of a system to be defined in terms of (Java) interfaces. These definitions are like vocabulary of the system as these do not contain implementation but just declarations. The system using the domain works against the interface and does not know what is going to be the implementation until run time. A factory, a broker or a container could actually help get an implementation during runtime. The key advantage is the layer that uses the interface is loosely coupled with implementation and there could be several implementations of the domain model that suits specific situations/needs. What other advantages does programming to the interface bring? And why not an abstract class instead of interface? This, year old interview “A Conversation with Erich Gamma” by Bill Venners best answers these questions.









