Bridge Pattern Code Review
Use the Bridge Pattern
Code Review
- Bridge Pattern: Define the Pattern Interface and Handler Objects
- Bridge Pattern: Define the Portal Object
- Bridge Pattern: Use the Bridge Pattern
Code Walkthrough
The Program class creates an instance of the PrinterPortal class "injecting" the different implementations of the Bridge classes.
class Program
{
static void Main(string[] args)
{
PrinterPortal portal;
portal = new PrinterPortal(new PrinterBridge.InkJetPrinter()); Console.WriteLine(String.Format("{0}\n", portal.printOperation())); portal = null;
portal = new PrinterPortal(new PrinterBridge.LaserPrinter()); Console.WriteLine(String.Format("{0}\n", portal.printOperation())); portal = null;
portal = new PrinterPortal(new PrinterBridge.DotMatrixPrinter()); Console.WriteLine(String.Format("{0}\n", portal.printOperation())); portal = null;
Console.Read(); } }
portal = new PrinterPortal(new PrinterBridge.InkJetPrinter()); Console.WriteLine(String.Format("{0}\n", portal.printOperation())); portal = null;
portal = new PrinterPortal(new PrinterBridge.LaserPrinter()); Console.WriteLine(String.Format("{0}\n", portal.printOperation())); portal = null;
portal = new PrinterPortal(new PrinterBridge.DotMatrixPrinter()); Console.WriteLine(String.Format("{0}\n", portal.printOperation())); portal = null;
Console.Read(); } }
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!