Java design mode GOF23 05 Adapter mode

Source: Internet
Author: User

I. Introduction to Adapter Mode

The simplest way for a class in Java to use another object that is irrelevant to itself is to use the adapter pattern.

The following is a simple code implementation:

 Package Com.lz.adapter; /*  */Publicclass  adaptee    {publicvoid request () {        System.out.println ("provides related services. ");    }}
 PackageCom.lz.adapter;/** Adapters with adapter interface are implemented*/ Public classAdapterImplementstarget{/** methods that are called by the member variable to be adapted to the object*/    Privateadaptee adaptee;  PublicAdapter (adaptee adaptee) {Super();  This. Adaptee =adaptee; } @Override Public voidHandlereq () {adaptee.request (); }}
 Package Com.lz.adapter; /*  */Publicinterface  Target    {void  handlereq ();}

here is like the computer wants to use the mouse to need the USB or the PS/2 interface to link the two, here the adapter will play a the role of the connection.

Java design mode GOF23 05 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.