Bridge mode, its role is to let the abstraction and implementation of separation, so that both can be changed.
For example, paint, I can draw rectangles, circles, triangles and so on, where to draw? I can draw on the PDF, or I can draw it on Doc. What pictures and where to draw can be independently changed, this kind of situation is more suitable for bridge mode. It means that there are more than one dimensional change in the design and we can use the bridge mode. If only one dimension is changing, then we can solve the problem satisfactorily with inheritance.
My graphic definition:
#pragma once
#include <vector>
#include "ImpShape.h"
class IShape
{public
:
IShape ( void);
Virtual ~ishape (void);
Virtual std::vector<point> getdrawpoints ();
void Paint ();
Public:
impshape *implementor;
All other graphics inherit:
#pragma once
#include "ishape.h"
class Crectangle: Public
ishape
{public
:
Crectangle (void);
~crectangle (void);
#pragma once
#include "ishape.h"
class Ccircle: Public
ishape
{public
:
ccircle (void );
~ccircle (void);
So how do you do it in the picture? I first define a shape's implementation class:
#pragma once
#include <vector>
class Impshape
{public
:
impshape (void);
Virtual ~impshape (void);
Public:
virtual void Draw (std::vector<point>&);
Then let the PDF and Doc's implementation classes inherit from Impshape:
#pragma once
#include "impshape.h"
class Imppdf: Public
impshape
{public
:
imppdf ( void);
~imppdf (void);
#pragma once
#include "impshape.h"
class Impdoc: Public
impshape
{public
:
Impdoc ( void);
~impdoc (void);