Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Which design pattern can be used when to decouple abstraction from the implementation?

Pragya Keshap answered on February 10, 2023 Popularity 3/10 Helpfulness 1/10

Contents


More Related Answers


Which design pattern can be used when to decouple abstraction from the implementation?

0

We can use Bridge design pattern to detach the implementation from

the abstraction.

Bridge is mainly used for separation of concern in design. We can

create an implementation and store it in the interface, which is an

abstraction. Where as specific implementation of other features can

be done in concrete classes that implement the interface.

Often Bridge design pattern is implemented by using Adapter

pattern.

E.g. we have Shape interface. We want to make Square and Circle

shapes. But further we want to make RedSquare, BlackSquare

shapes and GreenCircle, WhiteCircle shapes. In this case rather

than creating one hierarchy of all the shapes, we separate the Color

concern from Shape hierarchy.

So we create two hierarchies. One is Shape to Square and Shape to

Circle hierarchy. Another one is Color to Red, Black, Green, White

hierarchy. In this way we can create multiple types of shapes with

multiple colors with Bridge design pattern.

https://refactoring.guru/design-patterns/bridge/java/example#:~:text=Bridge%20is%20a%20structural%20design,the%20second%20hierarchy%20(Implementation).

Popularity 3/10 Helpfulness 1/10 Language java
Source: Grepper
Link to this answer
Share Copy Link
Contributed on Feb 10 2023
Pragya Keshap
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.