What is a two-way adapter template

GoF Design Patterns (Eric Gamma et al.) Mentions a two-way adapter template that is used for transparency. They are useful when 2 different clients want to view the same object in different ways. Can someone give a C ++ example for the same and in what practical scenarios can it be used?

+6
source share
3 answers

I find that the explanation given here is not bad. This is a C # example, but the explanation is clear, and the example can be easily translated into C ++ code. The example is also pretty detailed.

+2
source

Two-wire adapters are adapters that implement both the Target and Adaptee interfaces. The adapted object can be used as a Target in new systems related to target classes, or as an Adaptee in other systems related to Adaptee classes. Continuing this line of thinking, we can have adapters that implement n interfaces that adapt to n systems. Two-way adapters and n-shaped adapters are difficult to implement on systems that do not support multiple inheritance. If an adapter needs to extend the Target class, it cannot extend another class, such as an Adaptee, so the Adaptee must be an interface, and all calls must be delegated from the adapter to the Adaptee.

Adapter design pattern

Source: http://www.oodesign.com/adapter-pattern.html

+1
source

As Go4 explains (page 143 for me), this is an Adapter extension for multiple inheritance. Instead of extending one type of interface, the adapter class extends two.

0
source

Source: https://habr.com/ru/post/899267/


All Articles