Adapter Adapter Mode

Source: Internet
Author: User

Adapter Design Pattern Overview
Transforms the interface of one class into another interface that the customer wants. So that an interface that could not be called directly becomes callable

Advantages:
Make interfaces that are not intended for use suitable for use

Disadvantages:
Can only fit one class at a time, with certain limitations

 PackageCom.adapter; Public InterfaceUserdao { Public voidAdd ();  Public voidDelete ();  Public voidChange ();  Public voidfind ();} PackageCom.adapter;/** This is not very good, because I only need an add function, but because of the implementation of the interface, the interface is too many methods, I have to implement every abstract method. */ Public classUserdaoimplImplementsUserdao {@Override Public voidAdd () {System.out.println ("Add Action"); } @Override Public voidDelete () {} @Override Public voidChange () {} @Override Public voidfind () {}} PackageCom.adapter; Public classUseradapterImplementsUserdao {@Override Public voidAdd () {//TODO auto-generated Method Stub} @Override Public voidDelete () {//TODO auto-generated Method Stub} @Override Public voidChange () {//TODO auto-generated Method Stub} @Override Public voidfind () {//TODO auto-generated Method Stub    }} PackageCom.adapter;/** Using the adapter mode, the implementation class does not need to implement all the abstract methods, only need to use the method to rewrite it*/ Public classUserDaoImpl2extendsUseradapter {@Override Public voidAdd () {System.out.println ("New Action"); }} PackageCom.adapter; Public classUserdemo { Public Static voidMain (string[] args) {Userdaoimpl UI=NewUserdaoimpl ();        Ui.add (); USERDAOIMPL2 Ui2=NewUserDaoImpl2 ();    Ui2.add (); }}

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.