Java Bridge mode (bridges pattern) detailed _java

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.