Let us start looking at the Design Patterns:
http://en.wikipedia.org/wiki/Solid_(object-oriented_design)
http://en.wikipedia.org/wiki/GRASP_(object-oriented_design)
http://www.codeproject.com/KB/architecture/#Design+Patterns
http://apievangelist.com
http://apigee.com
http://www.objectaid.net/
http://www.learnerstv.com/
http://howtodoinjava.com/
[Liskov's Substitution Principle]
http://apigee.com
http://www.objectaid.net/
http://www.learnerstv.com/
http://howtodoinjava.com/
[Liskov's Substitution Principle]
http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
http://en.wikipedia.org/wiki/Don't_repeat_yourself
Adapter Pattern: Class Adapter vs Object Adapter:
- Class Adapter uses inheritance and can only wrap a class. It cannot wrap an interface since by definition it must derive from some base class.
- Object Adapter uses composition and can wrap classes or interfaces, or both. It can do this since it contains, as a private, encapsulated member, the class or interface object instance it wraps.The difference is subtle. Usually the later approach (favoring composition over inheritance) is the preferable as explained in the link which I'll quote here:Object-Oriented Programing (OOP) has too well known candidates for the reuse of functionality: Inheritance (whitebox reuse) and Composition (blackbox reuse). If you try to reuse code by inheriing from a class you will make the subclass dependent on the parent class. This makes a system in many cases unnecessarily complex, less testable and makes the exchange of functionality at run time unnecessarily hard. As a [Clean Code Developer] you should follow the Liskov Substitution Principle (LSP) when you need to decide if inheritance is appropriate.Composition means that one class uses another. You will further promote decoupling by defining the interfaces clearly. That will also give you the advantage that implementations can be easily replaced. So before you start applying the Liskov Substitution pronciple, think about the Favour Composition over Inheritance concept and ask yourselve why you shouldn't prefer composition right away."Because inheritance exposes a subclass to details of its parent's implementation, it's often said that 'inheritance breaks encapsulation'". (Gang of Four 1995:19)
No comments:
Post a Comment