Adapter Design Pattern

Adapter Design Pattern

you have old application which have access of some old component like this.

Now you introduce new component and this new component have new interface. client used to with old interface, so problem started, how to make sure client should not change his call.

Here Adapter pattern come in picture and help you, to make unrelated classes work together.


I have good example for this, when i was doing some application porting from windows to linux.
Window MFC have CFile class, but linux doesn't have this kind of class.
We had introduce a new class CFile and wrapper around C++ fstream object and provided same interface which is there for CFile.

Bingo problem resolved, not required much modification in client code, just added new class header.


www.desikudi.in

Proxy Design Pattern

Proxy Design Pattern


A simplest design pattern
just do hiding real object and introduce a placeholder.
use case :
when you want lazy initialization of real subject.
when do you want some other operation before making call on real object.
1. filtration of operation
2. logging of input.
3. after calling real object need to do logging of operation success or failure.

www.desikudi.in

Bridge Design Pattern

 Bridge Design Pattern 
Bridge Design Pattern


Simple one line design pattern : when do you need to do combinatorial hierarchy of classes.
handle/body idioms.

Example :
data structure implemented in two way of data.
1. Array form
2. List form

Now you need to create a Stack data strucutre hierarchy for
1. Stack basic interface.
2. StackHanoi only store push new element greater then top.
3. StackFIFO pop stack bottom element.

Now we will look diagram form of this hierarchy before using bridge pattern.
Before Bridge Design Pattern Class Hierarchy.

Now We will look when bridge design pattern used.
After Bridge Design Pattern Class Hierarchy


for code you can look sourcemaking.com . I just shared my understanding. If i got time and found some another example, I may share.

www.desikudi.in