Bridge
The bridge pattern has a hierarchy of abstraction classes
(not abstract classes) access implementation classes through
a hierarchy of implementation interfaces that parallels the
abstraction hierarchy. Also, a one (abstraction class) to
many (implementation) relationship is allowed for multiple
implementations of any abstraction.
Implementing this pattern is weird because of the following
C++ constraint.
In C++ a class cannot inherit an interface implementation.
By this I mean, given the following classes
NOTE: The methods are inlined
-----------------------------------------------------
class A
{
public:
void method_A(){};
};
-----------------------------------------------------
Another class
-----------------------------------------------------
class B
{
public:
void method_B(){};
};
-----------------------------------------------------
Here is the Interface.
-----------------------------------------------------
class I_AB
{
virtual void method_A() = 0;
virtual void method_B() = 0;
};
-----------------------------------------------------
This class inherits from A and B and I_AB
-----------------------------------------------------
class C : public A, B, I_AB
{
};
-----------------------------------------------------
If you try and instantiate an obect of type C
This will give the error:
cannot declare variable `cObject' to be of type `C'
because the following virtual functions are abstract:
virtual void I_AB::method_A()
virtual void I_AB::method_B()