Bridge pattern is categorized as a structural pattern in GoF because it structurally decouples abstraction from its implementation so that the two can vary independently. However, it is very similar to Strategy pattern which is categorized as a behavioral pattern. source: GoF overviewInstead of having one abstract class that defines the interface to the abstraction and its concrete subclasses implement it in different ways all in one class hierarchy, bridge pattern separates implementation from domain abstraction so either side can be reused or extended independently with respect to its own inheritance hierarchy: Domain Abstraction encapsulates (has a reference or references to) multiple Implementations and can initialize theseImplementation instances via the constructor. As a result, you may have any combination of different Abstraction and Implementations. For example, an image format class like JPG or PMG is on the Abstraction side, whereas displaying on Widows or Mac is on the Implementor side. The association from Abstraction to Implementation is a 'basic aggregation' (as opposed to composition aggregation) which means the Part Class (Implementation) instances can outlive its Whole Class (Abstraction). code example/** when to use bridge pattern
comparisonBridge vs. Strategy (very similar)
references
0 Comments
Leave a Reply. |
Categories
All
Archives
May 2020
|