JS design mode-Adapter mode

Source: Internet
Author: User

Description: The adapter mode looks like a façade mode on the surface. They all have to wrap other objects and change the interfaces they render. But the difference is how they change the interface. Façade elements represent a simplified interface that does not provide an additional choice, and sometimes it makes some assumptions in order to facilitate common tasks. Instead, the adapter converts an interface to another interface, which does not filter out certain functions or simplifies the interface .

Scenario: Interfaces that are intended for customer systems are incompatible with interfaces provided by existing APIs. It can only be used to coordinate grammatical differences. The two methods the adapter should perform should be a similar task, otherwise it will not solve the problem.

Example: If you have a function with 3 string arguments, but the client system has an array of three string elements, you can use an adapter to connect the two.

// String Object var clientobj = {    str1:"foo",    str2:"Bar",    str3:"Baz"}; // interface Functions function Interfacefn (STR1,STR2,STR3) {    //... .. }// adapter functions function   clienttointerfaceadapter (o) {    interfacefn (O.STR1,O.STR2,O.STR3);}

JS design mode-Adapter mode

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.