TechJour

Bridge Pattern – Mastering

Posted by: mshanm10 on: September 16, 2008

Decouple an abstraction from its implementation so that the two can vary independently -Gamma et al.

Understanding what a pattern is, just the start to mastering the patterns. Applying a pattern to a problem does make the design flexible but with the cost of complexity. So, the real challenge, when applying a particular pattern, is deciding its fit to the problem in hand.

Consider Bridge Pattern’s shape example mentioned here. Let’s consider two different problem domains and figure out if the bridge pattern is a best fit. In this case, Bridge pattern consists of Abstraction: Shape, Refined Abstraction: CircleShape, SquareShape, Implementor: DrawingAPI, Concrete Implementor: WindowsDrawingAPI, MacDrawingAPI or FirefoxAPI, IEAPI. Now consider the following problem domains.

Problem Domain 1: Developing an UI for a Client-Server application with different shapes to be drawn, supporting multiple operating systems.

Is bridge pattern suitable for this domain, consider factors 1. How many OS are available or needs to be supported 2. How often does a new OS emerge?. Lets say we have to support Windows, Mac and Unix ignoring its previous versions. With 3 OS’s needs to be supported and no new OS have emerged in past decade it may be a overkill to apply this pattern for this problem domain.

Problem Domain 2: Developing an UI for a web application with different shapes to be drawn, supporting multiple browsers.

There are tonnes of browsers available than we can imagine and new browsers emerge more often we dream, including chrome from google recently. This might not be the case in the long run, but until we reach there, we will be better off applying Bridge pattern to this problem domain.

Patterns suggest us a solution to a common problem and steers us in the right direction. Keep in mind Patterns doesn’t mandate a solution. To figure out, if a particular pattern, is the best fit for the problem depends on the problem domain and the master in you.

Tags:

Categories

Archives

Powered by FeedBurner

Flickr Photos

Vancouver under fog

Frozen Abiqua - 2

Sguardo a ovest

A Surprising Cup

More Photos