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
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;
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
see you later posts