Understanding Design Patterns (adapters)

Source: Internet
Author: User

Adapter mode, convert different interfaces, achieve compatibility.

Specific environment
  • Interface compatible
    -Use existing classes, but in a different way from the original, you need to convert
    -Existing interfaces are compatible with third-party components
    -Retains and uses the functionality of the original system class, but the client access mode changes while the original code cannot be modified

  • Conversion between similar functional classes

A class of questions

Incompatible interface classes, not cooperating

Solution Solutions

3 characters:

  • Destination interface target: Provides the expected usage, implemented by a class or interface
  • Adaptee by the appropriate ligand: the original use of the class, implemented by the class or interface
  • Adapter Adapter: Encapsulates the adaptee reference, implements or inherits Target, overrides the target method, encapsulates the Adaptee method
class adapters and Object adapters

Java does not support multiple inheritance and is not currently discussed

Advantages and Disadvantages

Pros:

  • reusing classes, reducing the amount of development
  • extensible Legacy class functionality
  • can be decoupled via the target interface, using multiple adapters
  • by the adapter to the interface user transparent
  • target interface and the adapter

Cons:
for object adapters, the adapter is more complex to write or modify

Because the original system is required to provide an interface (that is, the API of the adapter), and it needs to understand its applicable environment

Reference

Design Patterns Learning Notes-Adapter mode, Wang Juqiang

Understanding Design Patterns (adapters)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.