Bridge1. Substation: Structural mode 2. Condition: Typically, when a abstract class or interface has multiple specific implementation (Concrete Subclass), these Concrete may have the following: a. These specific implementations Just right, such as fight, you have to don't have some guys. Between the two, the actual application, often there is a conceptual overlap between these specific implementations. So we need abstract The common partial and behavioral joints are all independently open. It is ready to be placed in an interface, and now you need to design two interfaces, lay abstraction and behavior, respectively, and independent part of the common part of the action.) If the upper fight is guy to see what it is. What is the wooden, regulatory, brick, a large number, plus the original freehand plus the style of fight, is a tyranny or this smack .. .. The family of fights is also enough, and I understand a lot of inheritance, hang ...
3. Basic ideas: divide abstraction and behavior, each independent, but can dynamically bind.
4. Example / ** * The Abstract of fight * / public abstract class Fight {protected String name; public abstract void hitOthers (); public String getName () {return name;} protected FightImp getProps (String prop) {// factory IF (Prop.Equals ("knife") {Return new speedimpknife ();} else if ("brick")) {return new speedimpbrick ();} else {return new speedimpemPTY ();}}}
/ ** * The RefinedAbstraction * / public class FightCrazy extends Fight {FightImp prop; public FightCrazy (String prop, String name) {this.prop = getProps (prop); this.name = name;} public void hitOthers () {System .out.println ("Tale:" getName ()); prop.useprops ();}}
/ ** * The RefinedAbstraction * / public class FightSmart extends Fight {FightImp prop; public FightSmart (String prop, String name) {this.prop = getProps (prop); this.name = name;} public void hitOthers () {System .out.println ("Meter Agile:" GetName ()); Prop.UseProps ();}}
/ ** * the importimp {public interface fastimp {public abstract void useprops ();
/ ** * The contReteimplementor * / public class fastimpbrick imports frametimp {public void useprops () {system.out.println ("Domestic board brick, high quality and cheap. Please press 13xxxxxxxx to continue or order");}}
/ ** * The ConcreteImplementor * / public class FightImpKnife implements FightImp {public void useProps () {System.out.println ( "Houbei Shazhu Dao");}} / ** * The ConcreteImplementor * / public class FightImpEmpty implements FightImp {Public void useprops () {system.out.println ("Most Restaurant: Null Gloves White Wolf");}}
Abstract (FIGHT) - Defines the interface of an abstract class. - Maintain a pointer to the Implementor type object. . REFINEDABSTRACTION (Fightcrazy, Fightsmart) - Expanded the interface defined by the Abstraction. . Implementor (XXIMP) - Defines the interface of the implementation class, which does not have to be completely consistent with the ABSTRAction; in fact, these two interfaces can be completely different. In general, the Implementor interface only provides basic operations, and Abstraction defines a higher level of operation based on these basic operations. . ConcreteImplementor (XXXIMP) - Implement the implementation of the implementationor interface and defines the specific implementation thereof.
5. Incident: 1. BRIDGE mode execution class, such as "fight" and "props" are one-on-one relationship, correctly create Fightimp is the key to this mode, 2. There must be a behavior in the abstract common part. Its attribute is used as a method as its initial entrance: getProps (); 3. Add the behavior of "Behavi Properties" during the "Abstract Common" specific behavior, each REFINEDABSTRACTION has an IMP as its member variable , Polymerization
link:
1. Design mode (can be used for object-oriented software)
2. Design mode (Patterns in java) - http://www.jdon.com