Friday 31 July 2015

Program to an interface/abstract class, not an implementation Principle

  Program to an interface/abstract class , not an implementation

The goal here is to keep things flexible, as if things are inflexible, then were going to get into trouble further down the road, especially when we try to extend the application.
The  point here is to exploit polymorphism  by programing to a super-type (interface/abstract class) so that the actual run-time object isn't locked into the code. and we could rephrase "program to a super-type" as "the declared type of the variables should be a super-type, usually an abstract class or interface, so that objects assigned to those variables can be be of any concrete implementation of the super-type,  means the class declaring them doesn't have to know about the actual object types".

 

No comments:

Post a Comment