Headfirst Design Mode Study Notes 4-adapter mode & Appearance Mode

Source: Internet
Author: User
Adapter Mode

The core idea of the adapter mode is to encapsulate the interfaces of the adapter for the client to call. Class diagram:

Adapter. Target is the object type that the customer sees as being operated on. The Adapter inherits from it, so it shows the type of the target class. Then, encapsulate the real implemented object interface internally, so that the customer can execute the adaptee implementation for the action called by the target object.

Applicable scenarios of the adapter principles:

I want to use an existing class, but the interface is not very timely. Adding the middleware adapter allows the caller to be compatible with the called module.

Minimum knowledge Principle

Reduce interaction between objects. A class should call only the data as much as possible:

L object itself

L objects passed as parameters

L object created or instantiated by this method

L any component of the object

 

Appearance Mode

Application scenarios:

Simplify and unify a complex set of interfaces to provide a simple interface externally.

 

 

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.