Difference between Bridge pattern and Adapter pattern

后端 未结 9 1028
清歌不尽
清歌不尽 2020-11-29 19:16

What is the difference between the Bridge and Adapter patterns?

9条回答
  •  独厮守ぢ
    2020-11-29 19:46

    http://en.wikipedia.org/wiki/Adapter_pattern

    The Adapter pattern is more about getting your existing code to work with a newer system or interface.

    If you have a set of company-standard web service APIs that you'd like to offer to another application's existing extensibility interface, you might consider writing a set of adapters to do this. Note that there's a grey area and this is more about how you technically define the pattern, since other patterns like the facade are similar.

    http://en.wikipedia.org/wiki/Bridge_pattern

    The Bridge pattern is going to allow you to possibly have alternative implementations of an algorithm or system.

    Though not a classic Bridge pattern example, imagine if you had a few implementations of a data store: one is efficient in space, the other is efficient in raw performance... and you have a business case for offering both in your app or framework.

    In terms of your question, "where I can use which pattern," the answer is, wherever it makes sense for your project! Perhaps consider offering a clarification edit to guide the discussion on where you believe you need to use one or the other.

提交回复
热议问题