Adapter design patterns used in Java development

Source: Internet
Author: User

 PackageShipeiqidemo;/** A common design pattern in Java: Adapter * Source: A subclass to implement the interface, then you have to implement the interface of all the abstract methods, sometimes the abstract method * a lot, but do not need to implement all, so at this time define an abstract class to implement this interface, and then through the subclass to inherit * In this abstract class, this abstract class is referred to as the adapter*/ Public classShipeiqidemo { Public Static voidMain (string[] args) {//Zhuozi zz = new Zhuozi (); //Zz.open (); //zz.close ();Windows W =NewZhuozi ();    W.open ();    W.close (); W.stop ();}}//write an interface with more abstract methodsInterfacewindows{ Public Abstract voidopen ();  Public Abstract voidClose ();  Public Abstract voidstart ();  Public Abstract voidstop ();}//write an abstract class to implement this interface is the adapterAbstract classDoorImplementswindows{//all rewrite the abstract method inside windows, but the method body is empty, let subclass to implement     Public  voidopen () {};  Public voidclose () {};  Public  voidstart () {};  Public  voidstop () {};}//write a subclass to inherit doorclassZhuoziextendsdoor{ Public  voidOpen () {System.out.println ("hello!!"); }     Public voidClose () {System.out.println ("world!!"); }}

Adapter design patterns used in Java development

Related Article

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: [email protected] 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.