CSC/ECE 517 Fall 2012/ch2b 2w22 sk
Requirements
The introduction to the GoF book gives three principles for writing reusable and flexible software.
- Program to an interface, not an implementation.
- Favor object composition over class inheritance.
- Consider what should be variable in your design (originally, Encapsulate the behavior that varies).
Explain these principles, and illustrate them with original examples.
Program to an interface, not an implementation
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma
In this principle, the word interface is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has keyword by the same name. Interface in this context is relates to the OO principle of capabilities that the object(s)is(are) able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically.
For example:
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation.
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last. That's been an important theme of Eclipse development since we started. We have built Eclipse as a platform. We always keep in mind as we design Eclipse that it has to last ten or twenty years. This can be scary at times.
Favor object composition over class inheritance
Consider what should be variable in your design
REFERENCES
<references/>
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/
http://www.artima.com/lejava/articles/designprinciples.html
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html
http://www.amazon.com/gp/product/0596007124?ie=UTF8&tag=fatagnus-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=0596007124
http://www.amazon.com/gp/product/0201633612?ie=UTF8&tag=fatagnus-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=0201633612