The bridging pattern is defined as separating the abstract part from its implementation, so that both can be independently changed.
The first time to look at the design pattern, not very clear the meaning of this sentence, along with the author's continuous development, found that there is a scene,
Inheritance relationship is more, not easy to maintain the parent class, and I think the emergence of bridging mode is a good solution to this problem. Resolving inherited parent classes with aggregations is difficult to maintain. First look at the bridge mode design.
Liar design mode-Class diagram
The above class diagram is very simple and easy to understand, first look at the author's demo
/***/Publicinterface ioperate {publicvoid operate ();}
/*** Brand parent category*/ Public classBrand {PrivateIoperate operate; PublicBrand (ioperate operate) {Super(); This. operate =operate; } Public voidoperate () {operate.operate (); } Publicioperate getoperate () {returnoperate; } Public voidSetoperate (ioperate operate) { This. operate =operate; }}
/** * play games */ public class Game implements ioperate{@Override public void operate () {System.out.prin TLN ( play the game "
/** * see contacts */ public class maillist implements ioperate {@Override public void operate () {SYSTEM.OUT.P RINTLN ( see Address Book
/** * M brand */ public class mbrand extends brand{ public Mbrand (Ioperate operate) { super (operate); }}
/***/Publicclassextends brand{ public Nbrand (ioperate operate) { Super(operate); }}
/*** Client*/ Public classTest { Public Static voidMain (string[] args) {ioperate game=NewGame (); Ioperate maillist=Newmaillist (); Brand Nbrand=NewNbrand (game); Nbrand.operate (); Nbrand=NewNbrand (maillist); Nbrand.operate (); Brand Mbrand=NewMbrand (game); Mbrand.operate (); Mbrand=NewMbrand (maillist); Mbrand.operate (); }}
The operation results are as follows
Play games see contacts play games See contacts
Better understand, but I think we in the actual development, may be used in many places bridge mode, but we all forget this mode, and with inheritance to achieve.
Still the old saying, understand its core thought, refuse to mechanically. A small partner who wants to help learn bridging patterns.
Java Bridging mode (Liar design mode)