Original Post
Hi folks, Looking over some past papers and one of the questions asks to compare the strategy and bridge patterns and clearly state the difference between them. I have been wracking my brains all day and cannot see it, they are so similar that I can't see what the difference is. My current understanding is this: Strategy pattern: You wish to reduce coupling and code repetition for a given task, but the given task is relatively common (e.g. two types of bank account withdrawal, one with a fee and one without), so you implement a strategy by using an abstract class or interface, with concrete subclasses implementing the exact detail of the operation. This is preferable to having a Withdraw() method declared virtual in the Account baseclass as that leads to spurious code repetition and a higher level of coupling. You might have AccountWithdrawal foo = new AccountWithdrawalWithFee();, to use polymorphism, and assign that to an account representing a bank account. So you can then have BankAccount.withdraw(); and it knows to use the AccountWithdrawalWithFee() to perform the right strategy. Bridge pattern: You have an abstract class called Shape and off of it you have subclasses called Rectangle and Circle. You have a class called Draw, an instance of which is included in the Shape class. Draw has two separate drawing packages called DrawingType1 and DrawingType2, so again you would do Draw foo = new DrawingType1(); and assign it to the Shape object, which you might create as Shape bar = new Rectangle();. I am struggling so hard to see what the difference is here. As far as I can see the two patterns are exactly the same or is my understanding flawed? Have I even got the patterns right at all? I'm confused and any help would be greatly appreciated. I have Googled this to death and the explanations I'm getting are either very confusing, contradictory or don't explain the difference clearly. TIA, ukd.