bridge pattern

Started by
2 comments, last by derek7 17 years, 11 months ago
I think key in bridge pattern is composition. two way in object communication: derive and composition. abstract interface(virtual function) use derivation to hide implemtation. brideg parrtern use composition to hide implementaion. right? what do you think of?
Advertisement
I'm totally agree on the fact that the bridge design pattern could be used for hiding implementation.
But by the way this should not rely on composition to be done.
What 'll follow could be seen as a form of bridge design pattern :

For instance you may declare your nested implementation class inside the private zone of the class and add a
pointer to it inside your class like :

// in the header file implementation.h#ifndef IMP_H#define IMP_Hclass foo{   class imp ;   class * imp ;public :    // members functions  .....};#endif //IMP_H


and in your source implementation file
// in imp source file #include "implementation.h"class imp {   // the implementation };


No object inside the first class , no composition .

One of the biggest benefits of the Bridge , according to me , is that you don't have to recompile the whole files of your project that depend on your class .Thus if you make change in your implementation source file and that another source file includes your header they won't have to be recompiled ( except in case of extreme modifications that should impact deeply the way member function or object of your class are used ).

ps : english is not my native langague so don't flame the grammar errors please.

ok both bridge and proxy introduce a level of indirection when accessing an object.


they seem to be similar , who tell me the different between them? I think they are only some tiny different. they are almost the same design patterns.
Another question:
A virtual proxy can perform optimizations such as creating an object on demand. -- from desgin patterns

I see no need visual proxy pattern.
look at below, I can do create object on demand in a simple class. why need the virtual proxy ?

class A{getFileValue()private: 	Ruse * mRuse; // the data from file	Cloth mCloth;	bool loaded;};A::getFileValue(){	if( loaded )	{		return mRuse;	}	else	{		load();		return mRuse;	}}A::getCloth(){    return mCloth;}A a;a.getCloth();  // get little objecta.getFileValue() // get file content 


[Edited by - derek7 on May 21, 2006 11:43:44 PM]

This topic is closed to new replies.

Advertisement