Tapio Niemela wrote:thanks for your reply. So Bridge pattern is just "simply" combination of template method and strategy? Then it would make some sense, lots of examples were missing that template method part..
Tapio
Its more than just using the template and strategy patterns. Gamma et. al. state that the intent of the Bridge pattern is to, "
Decouple an abstraction from its implementation so that the two can
vary independently". The keywords here are "decouple" and "vary". The strategy pattern does the decoupling and the template pattern allows strategy subclasses to vary in a structured manner. For example, consider a large object that encapsulates a financial option on a bond. Using the Bridge pattern you could refactor out of this object the instructment being sold to allow it to encapsulates bond, stocks, etc. You could also use the Bridge pattern to refactor out the pricing model, with one strategy being a BlackScholesPriceModel class and another being a BinomialPricingModel class.
(There was a great article on the Bridge Pattern in the
Journal of Object-Oriented Programming (JOOP) several years ago that used the above example)