Monday, July 18, 2011

[Tutorial] Common Design Patterns in C# 4.0
Part8: Bridge Pattern

Pattern Name:
Bridge Pattern

Short Description:
Separate implementation and object interfaces

Usage: 
Sometimes used, useful to decouple an abstraction from its implementation and to be able to modify them independently.

Note that the Bridge pattern has nearly the same structure as the Adapter Pattern. But it is used when designing new systems instead of the Adapter pattern which is used in already existing systems.

Complexity:
1 / 5

UML Class Diagram:

image

Explanation:

  • The abstract Repository class defines the interface that all inheriting refined Repository classes will use for object management purposes.
  • Note that the operations within the Repository classes define high-level operations.

image

  • The refined Repositories extend the basic functionalities and implement the execution code that uses the implementation classes. They should contain specializations which only apply to specific Repositories. 

image

  • The abstract DataObject class defines the interfaces of the implementation classes. Note that the abstract Repository and the abstract DataObject classes can have completely different interfaces.
  • The concrete DataObject implementations contain the code that executes all the low-level operations.
  • Note that the methods within the Repository class could also call multiple methods in the implementation classes (1 to * relationship).

image

image

  • In the last step we add some code to test the software design and the Bridge implementation.

image

  • When running the example you can see that everything is working as expected and that the correct classes are instantiated during runtime.
image
Source Code:
http://csharpdesignpatterns.codeplex.com/

Share/Save/Bookmark

No comments: