![]() |
VOOZH | about |
The bridge method is a Structural Design Pattern that allows us to separate the Implementation Specific Abstractions and Implementation Independent Abstractions from each other and can be developed considering as single entities.
The bridge Method is always considered as one of the best methods to organize the class hierarchy.
Consider the following class Cuboid which has three attributes named length, breadth, and height and three methods named ProducewithAPI1(), ProduceWithAPI2(), and expand().
Out of these, producing methods are implementation-specific as we have two production APIs, and one method i.e., expand() method is implementation-independent.
Till now we have only two implementation-specific methods and one implementation-independent method but when the quantity will rise (of course in a large-scale project) things will become messy for the developers to handle.
Note: Following code is written without using the Bridge method.
Now let's look at the solution for the above problem. The bridge Method is one of the best solutions for such kinds of problems. Our main purpose is to separate the codes of implementation-specific abstractions and implementation-independent abstractions.
Note: Following Code is written using Bridge Method
Following is the UML diagram for Bridge Method
Further read: Bridge Method in Java