Benefits of adapter Mode

Source: Internet
Author: User
When the caller uses the "management class" method, write a call similar to the following: Code :

Idbmembernamecardmanager ncmgr = Memberfacade. getinstance (). createdbmembernamecardmanager ();
Imembernamecard NC = Ncmgr. readmembernamecard (currentmember. ID );
// Display the company name in the business card in the label
This . Labelcompany. Text = NC. Company;

In this way, the caller needs to know
1. The domain information interface is the aforementioned interface imembernamecard and currentmember (current user), that is, the domain class ".
2. Method interface for accessing domain information, that is, the aforementioned idbmembernamecardmanager, also known as "Management (manager) Class ".
3. Obtain the facade of the management class, that is, the above memberfacade, that is, the class factory.

Now we use another mode:

Imembernamecardadapter Adapter = (Imembernamecardadapter) currentmember. getadapter ( Typeof (Imembernamecardadapter ));
If (Adatper ! =   Null )
{
Imembernamecard NC = Adapter. readmembernamecard ();
This . Labelcompany. Text = NC. Company;
}

In this way, the caller only needs to know domain information and access interfaces. Does it look more concise?
This mode is widely used in eclipse. You can add many different adapters to the domain class without requiring the domain class to directly implement new interfaces, thus avoiding "interface swelling ".
The less customers know the better, I think this is the essence of this model.

Note: The support for this mode requires some environment support. I have also uploaded a C # project about the adapter mode to simulate this support.

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.