Java Bridge mode
Bridge mode decoupling, its implementation of the definition. It is a structural pattern. This mode involves the interface acting as a bridge. This bridge makes the concrete class independent of the interface performer class.
Bridge mode decoupling, its implementation of the definition. It is a structural pattern.
This mode involves the interface acting as a bridge. This bridge makes the concrete class independent of the interface performer class.
These two types of classes can be changed without affecting each other.
Instance:
Interface Printer {public void print (int radius, int x, int y);} From WWW.J a v A2 s. C OM class Colorprinter implements Printer {@Override public void print (int radius, int x, int y) {System.out.pri
Ntln ("Color:" + Radius + ", x:" +x+ "," + y + "]); Class Blackprinter implements Printer {@Override public void print (int radius, int x, int y) {System.out.prin
TLN ("Black:" + Radius + ", x:" +x+ "," + y + "]);
} abstract class Shape {protected Printer print;
Protected Shape (Printer p) {this.print = P;
public abstract void Draw ();
Class Circle extends Shape {private int x, y, radius;
public Circle (int x, int y, int radius, Printer draw) {super (draw);
this.x = x;
This.y = y;
This.radius = radius;
public void Draw () {print.print (radius,x,y); } public class Main {public static void main (string[] args) {Shape redcircle = new Circle (100,100, New Colorp
Rinter ()); Shape blackcircle = new Circle (100, Blackprinter, New ());
Redcircle.draw ();
Blackcircle.draw ();
}
}
Thank you for reading, I hope to help you, thank you for your support for this site!