Decorator Pattern: Sean Chambers has written a good article here on the decorator pattern. There is a free chapter in the OReilly book available here. In a nutshell, this pattern comes handy if you want to extend classes at runtime instead of compile time using a form of object composition. By dynamically composing objects, we are making sure the Open Close principle is not violated. Meaning, new functionality is added without modifying base class. The pattern does what Inheritance will help accomplish just its more powerful and is executed at runtime. C# example is IO operations using streams. File Streams, Memory Streams, Buffered steams and the like.
![]() |
| Courtesy: MSDN |
Adapter Pattern: The Adapter pattern lets you adapter one interface to another. This is the best way to deal with that legacy monster that is hard to test. Create an interface and it will hide the ugliness and help test the code too! It is different than the decorator pattern in the sense that in Decorator Pattern the interface of the objects you are composing is the same while in Adapter you change the interfaces. Adapters also have a definite sequence to them; the Adaptee must be contained by the Adapter.
Composite Design Pattern: Ray Houston from LosTechies has a good article here. In a gist: Its best for handing tree like structures where the parent and leaf nodes does not have to be dealt differently.

No comments:
Post a Comment