Java -Brückenmuster (Brückenmuster)
Entkopplung des Brückenmodus, seine Implementierungsdefinition. Es ist ein strukturelles Muster. Dieser Modus umfasst Schnittstellen, die als Brücken fungieren. Diese Brücke stellt bestimmte Klassen unabhängig von Interface -Implementierern her.
Entkopplung des Brückenmodus, seine Implementierungsdefinition. Es ist ein strukturelles Muster.
Dieser Modus umfasst Schnittstellen, die als Brücken fungieren. Diese Brücke stellt bestimmte Klassen unabhängig von Interface -Implementierern her.
Diese beiden Klassenarten können geändert werden, ohne sich gegenseitig zu beeinflussen.
Beispiel:
Schnittstellendrucker {public void print (int radius, int x, int y);} // von www.jav a2 s. c omclass colorprinter implementiert drucker {@Override public void print (int radius, int x, int y) {System.out.println ("Farbe:" +radius +", x:" +x +"," +y +"]"); }} class Blackprinter implementiert Drucker {@Override public void print (int radius, int x, int y) {System.out.println ("schwarz:" +radius +", x:" +x +"," +y +"]"); }} abstrakte Klasse Form {geschützter Druckerdruck; geschützte Form (Drucker p) {this.print = p; } public abstract void Draw (); } Class Circle erweitert die Form {private int x, y, radius; public circle (int x, int y, int radius, drucker 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) {form Redcircle = neuer Kreis (100.100, 10, neuer Colorprinter ()); Form BlackCircle = neuer Kreis (100.100, 10, neuer Blackprinter ()); redcircle.draw (); BlackCircle.draw (); }}Danke fürs Lesen, ich hoffe, es kann Ihnen helfen. Vielen Dank für Ihre Unterstützung für diese Seite!