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