Design mode--Adapter (Adapter) mode

Source: Internet
Author: User

Today learning another design pattern, adapter (Adapter) mode, which is a common direction, but with special requirements, is applied to this design pattern. Write here, think of a long time ago, have written an article "ASP." NET Adapter design mode (Adapter) http://www.cnblogs.com/insus/archive/2013/02/04/2891426.html, but does not seem to have the flavor of the adapter.

such as a system, the development of a variety of design permissions, but a certain, customer requests, requires a special permission to operate. Have to develop an adapter to have this special operation permission.

Use code to give an example.

Define the interface first:



When developing, we need to subdivide, read, write, delete ..., which produces a lot of subdivision classes:

Read:



Write:



By deleting:

And so on, here are the special requirements that allow some operators to have write and delete permissions, so a special adapter needs to be developed:

Client implementations:



Operation Result:

Design mode--Adapter (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.