Presentation is loading. Please wait.

Presentation is loading. Please wait.

BRIDGE PATTERN.

Similar presentations


Presentation on theme: "BRIDGE PATTERN."— Presentation transcript:

1 BRIDGE PATTERN

2 Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern comes under structural pattern as this pattern decouples implementation class and abstract class by providing a bridge structure between them. This pattern involves an interface which acts as a bridge which makes the functionality of concrete classes independent from interface implementer classes. Both types of classes can be altered structurally without affecting each other. We are demonstrating use of Bridge pattern via following example in which a circle can be drawn in different colors using same abstract class method but different bridge implementer classes.

3 Intent Decouple an abstraction from its implementation so that the two can vary independently. Also Known As Handle/Body

4 Applicability Use the Bridge pattern when
• you want to avoid a permanent binding between an abstraction and its implementation. This might be the case, for example, when the implementation must be selected or switched at run-time. • both the abstractions and their implementations should be extensible by subclassing. In this case, the Bridge pattern lets you combine the different abstractions and implementations and extend them independently. • changes in the implementation of an abstraction should have no impact on clients; that is, their code should not have to be recompiled

5 • Participants Abstraction (Window)
o defines the abstraction's interface. o maintains a reference to an object of type Implementor. • RefinedAbstraction (IconWindow) o Extends the interface defined by Abstraction. • Implementor (WindowImp) o defines the interface for implementation classes. This interface doesn't have to correspond exactly to Abstraction's interface; in fact the two interfaces can be quite different. Typically the Implementor interface provides only primitive operations, and Abstraction defines higher-level operations based on these primitives. • ConcreteImplementor (XWindowImp, PMWindowImp) o implements the Implementor interface and defines its concrete implementation.

6 Collaborations Abstraction forwards client requests to its Implementor object.

7 Implementation We have a DrawAPI interface which is acting as a bridge implementer and concrete classes RedCircle, GreenCircle implementing the DrawAPI interface. Shape is an abstract class and will use object of DrawAPI. BridgePatternDemo, our demo class, will use Shape class to draw different colored circle.

8

9 Step 1 - Create bridge implementer interface.

10 Step 2 - Create concrete classes extending the above class.

11 Step 3 - Create an abstract class Shape using the DrawAPI interface.

12 Step 4 - Create concrete class implementing the Shape interface.

13 Step 5 - Create an abstract class Shape using the DrawAPI interface.

14


Download ppt "BRIDGE PATTERN."

Similar presentations


Ads by Google