Java implementation bridging (bridge) mode

Source: Internet
Author: User

Class Diagram:


/** * Mobile phone case, set * @author Stone * */public abstract class Basecellphoneshell {public abstract void mapping ();//Match what kind of phone}
/** * Mobile phone, bridging the phone shell Basecellphoneshell * @author Stone */public abstract class Basecellphone {private Basecellphoneshell shell ;p ublic void Setshell (Basecellphoneshell shell) {This.shell = shell;} Public Basecellphoneshell Getshell () {return shell;} public abstract void mapping ();//corresponds to which Shell}

/** * Mobile Implementation * @author Stone * */public class Cellphone extends Basecellphone {@Overridepublic void mapping () {SYSTEM.OUT.P RINTLN ("This phone corresponds to the shell is:"); Getshell (). mapping ();}}

/** * Mobile phone shell implementation * @author Stone * */public class Cellphoneshell extends Basecellphoneshell {@Overridepublic void mapping () {S Ystem.out.println ("shell----Iphone6");}}

/* Bridging (Bridge) mode, is a structured pattern *  * The abstraction and implementation decoupling, so that they can be independent changes, that is, the strong association between them into a weak association, * refers to the abstraction and implementation of a software system between the use of a combination/aggregation relationship rather than inheritance, So that the two can change independently. */public class Test {public static void main (string[] args) {/* * In this case: there is a strong correlation between the phone and the phone shell: either the phone corresponds to a shell (Basecellphoneshell), Either the shell corresponds to a cell phone (basecellphone) * Mobile phone can have multi-dimensional changes, such as according to the brand division, according to the size of the division according to the individual needs of the mobile phone shell also has a multidimensional change, because it to adapt the above divided mobile phone * will bridge in the Basecellphone , the aggregation is connected to the Basecellphoneshell */basecellphone cellphone = new cellphone (); Cellphone.setshell (new Cellphoneshell ());// converged access cellphone.mapping ();}}


Java implementation bridging (bridge) 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.