Inbali
Inbali

Reputation: 351

Regarding implement of a 'Bridge' pattern in C#

I'm tring to implement a Bridge pattern in my application,and I'm facing a problem I can't resolve:
Assume I'm having a general 'Abstraction' class in wich I want to have several implements,call them ImpA & ImpB.
When I do this:

Abstraction a = new Abstraction(new ImpA);

a.

After the dot,I expected to see the list of public properties/methods of the class ImpA,but I can't get to them unless I put them in Abstraction itself.
I absoulotly don't want to put all methods in the Abstraction because I want each implement would be indepent,and not having all in 1 class.
What do I miss here??

Upvotes: 1

Views: 280

Answers (1)

DeCaf
DeCaf

Reputation: 6086

The point of the Abstraction class is to abstract away from the implementation (ImpA) in your case. This means that the Abstraction class should define the interface (methods) that the client is supposed to use, and then propagate, or "translate" these calls to operations on the implementation. This of course means that you need to implement the methods composing your public interface in the Abstraction class and have these call the implementation.

If you just want to let the actual implementation class vary but the interface of them be the same and all exposed to the client, simply define an interface describing the public methods of your "ImpA" class and use the interface from the client.

You can find a .NET description of the Bridge pattern here: http://www.dofactory.com/Patterns/PatternBridge.aspx#_self1

Upvotes: 5

Related Questions