Sign in to follow this  
derek7

bridge pattern

Recommended Posts

derek7    100
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?

Share this post


Link to post
Share on other sites
Code Alchemist    122
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_H

class 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.

Share this post


Link to post
Share on other sites
derek7    100
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.

Share this post


Link to post
Share on other sites
derek7    100
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 object

a.getFileValue() // get file content





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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this