Business Object (similar to Coffee)
Implement some abstract business operations, such as searching for all orders from a user. DAOImplementor is used for all database operations.
Data Access Object (similar to CoffeeImp)
Abstract operations on database resources.
DAOImplementor such as OrderDAOCS, OrderDAOOracle, and OrderDAOSybase (similar to MilkCoffeeImp FragrantCoffeeImp)
For specific database operations, such as insert into statements, OrderDAOOracle is Oracle OrderDAOSybase is Sybase Database.
Database (Cloudscape, Oracle, or Sybase database via jdbc api)
Bridging ModeOverviewSeparate the abstract part from its implementation part so that they can all change independently.
Applicability1. You do not want to have a fixed binding relationship between the abstraction and its implementation. For example, this may be because the implementation part of the program should be selected or switched during the runtime. 2. Class abstraction and its implementation should be expanded by generating subclass methods. In this case, the Bridge mode allows you to combine different abstract interfaces and implementation parts and expand them separately. 3. Modifications to an abstract implementation part should not affect the customer, that is, the customer's Code does not have to be re-compiled. 4. As shown in the first class diagram in Figure 1, there are many classes to be generated. Such a hierarchical structure indicates that an object must be divided into two parts. 5. You want to share the implementation among multiple objects (reference count may be used), but the customer is not required to know this.
Participants1. Define Action defines the abstract class interface. Maintain a pointer to an Implementor object. 2. RefinedAbstraction expands the interface defined by the specified action. 3. Implementor defines the interface for implementing classes. This interface does not have to be exactly the same as the interface for implementing actions. In fact, these two interfaces can be completely different. Generally, the Implementor interface only provides basic operations, while the role Action defines high-level operations based on these basic operations. 4. ConcreteImplementor implements the Implementor interface and defines its specific implementation.
Class Diagram ExampleInvalid actionpublic abstract class Person { private Clothing clothing; private String type; public Clothing getClothing() { return clothing; } public void setClothing() { this.clothing = ClothingFactory.getClothing(); } public void setType(String type) { this.type = type; } public String getType() { return this.type; } public abstract void dress();}
RefinedmediaactionPublic class Man extends Person {public Man () {setType ("Man");} public void dress () {Clothing clothing = getClothing (); clothing. personDressCloth (this );}}
Public class Lady extends Person {public Lady () {setType ("");} public void dress () {Clothing clothing = getClothing (); clothing. personDressCloth (this );}}
Implementorpublic abstract class Clothing { public abstract void personDressCloth(Person person);}
ConcreteImplementorPublic class Jacket extends Clothing {public void personDressCloth (Person person) {System. out. println (person. getType () + "wear vest ");}}
Public class Trouser extends Clothing {public void personDressCloth (Person person) {System. out. println (person. getType () + "Pants ");}}
Testpublic class Test { public static void main(String[] args) { Person man = new Man(); Person lady = new Lady(); Clothing jacket = new Jacket(); Clothing trouser = new Trouser(); jacket.personDressCloth(man); trouser.personDressCloth(man); jacket.personDressCloth(lady); trouser.personDressCloth(lady); }}
ResultMen wear vests men wear trousers women wear vests women wear trousers