Bridge Design Pattern

In this post,You will find an example related bridge design pattern from stuctural pattern.

Decouple an abstraction from it’s implementation so that the two can vary independently. This sentence is a definition for bridge design pattern by GoF and intent of pattern.Pattern prefer composition instead of inheritance

Click the links for more information (sourcemaking.com , dofactory.com , oodesign.com etc.)

Let’s take a look some example scenarios

  • Logging mechanism; various types and formats (Eventlog,Database Logger,txt logger,) for logging
  • Files print for various formats(pdf,word,excel); print process and setting different for file formats
  • You can see .NET provider model for bridge design pattern
  • Shape and Pattern ; A square can be lined, unlined,solid and colourful.In the mean time these are valid rectangles and triangles

Our example scenario is about reporting.Reporting is crucial for companies.The output of each report can be different files formats.We will do a developing  for that case.

Before using the pattern;

_1

Design consist of very the class,it need defined class according to the output formats(excel,office) for reporties and, most importantly depth of inheritance

After using the pattern

Here is codes

Let’s look class diagram of the above codes

-2

see you later posts

Leave a Reply

Your email address will not be published. Required fields are marked *