Simple Note
From reference:
The bridge pattern is a design pattern used in software engineering which is meant to "decouple an abstraction from its implementation so that the two can vary independently". The bridge uses encapsulation, aggregation, and can use inheritance to separate responsibilities into different classes.
When a class varies often, the features of object-oriented programming become very useful because changes to a program's code can be made easily with minimal prior knowledge about the program. The bridge pattern is useful when both the class as well as what it does vary often. The class itself can be thought of as the implementation and what the class can do as the abstraction. The bridge pattern can also be thought of as two layers of abstraction.
Difference between Bridge Pattern and Adapter Pattern:
See reference.
Program
https://github.com/benbai123/JSP_Servlet_Practice/tree/master/Practice/JAVA/DesignPattern/src/bridge
Run TestMain.java to test.
Assume there are several calculator implements interface DesiredCalculator and you access them via a Bridge class rather than access them directly.
Once the API of DesiredCalculator is changed, you just need to update the content within Bridge class, all other parts of your program can stay unchanged.
References:
Bridge pattern
Difference between Bridge pattern and adapter pattern
No comments:
Post a Comment