Suggest an editImprove this articleRefine the answer for “What types of adapters exist?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)There are three main types of adapters: **class**, **object**, and **two-way**. Each implements the idea of compatibility in its own way. **Key point:** the object adapter, built on composition, is the most common variant (Java, C#, Python) because it is more flexible and less tightly coupled to a specific class than the class adapter.Shown above the full answer for quick recall.Answer (EN)ImageThere are three main types of adapters: **class**, **object**, and **two-way**. Each implements the idea of compatibility in its own way. --- ### 1. **Class Adapter** Implemented via **inheritance**: the adapter **inherits the client's interface** and at the same time **inherits (or implements) the adapted class**. Used where the language supports multiple inheritance (for example, C++). **Scheme:** Client → Adapter (inherits Target and Adaptee) → Adaptee **Characteristics:** - High performance (no delegation). - Cannot be applied without multiple inheritance. - Tight coupling to the adapted class. **Example (C++):** ```cpp class Adapter : public Target, private Adaptee { public: void request() override { specificRequest(); } }; ``` --- ### 2. **Object Adapter** Uses **composition**: the adapter **holds a reference to the adapted object internally** and delegates calls to it. This is the most common variant in Java, C#, and Python. **Scheme:** Client → Adapter (contains Adaptee) → Adaptee **Characteristics:** - Flexibility: different objects can be adapted at runtime. - Less coupling (the adapter does not depend on a specific class). - Slightly higher overhead due to delegation. **Example (Java):** ```java class Adapter implements Target { private Adaptee adaptee = new Adaptee(); public void request() { adaptee.specificRequest(); } } ``` --- ### 3. **Two-Way Adapter** Allows **mutual compatibility**: the client can work through both the `Target` interface and the `Adaptee` interface. That is, the same adapter can translate calls **in both directions**. **Used:** - when integrating two legacy systems where both sides need to be made to "get along"; - in network protocols, API gateways, drivers. **Characteristics:** - More complex implementation. - Often used at the middleware level and in bidirectional interfaces. --- ### 4. **Conclusion** | Adapter type | Principle | Relation to Adaptee | Advantages | Disadvantages | |---|---|---|---|---| | Class | Inheritance | Tight | Faster, simpler | Inflexible, requires multiple inheritance | | Object | Composition | Reference | Flexible, safe | Slower, more code | | Two-way | Both sides | Mutual | Universal | Complex to implement | **Summary:** Class adapter is fast but rigid. Object adapter is flexible and safe (the most common). Two-way adapter is universal but complex.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.