<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>http://rasimsen.com/index.php?action=history&amp;feed=atom&amp;title=Bridge_Design_Pattern</id>
	<title>Bridge Design Pattern - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://rasimsen.com/index.php?action=history&amp;feed=atom&amp;title=Bridge_Design_Pattern"/>
	<link rel="alternate" type="text/html" href="http://rasimsen.com/index.php?title=Bridge_Design_Pattern&amp;action=history"/>
	<updated>2026-04-22T13:36:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>http://rasimsen.com/index.php?title=Bridge_Design_Pattern&amp;diff=574&amp;oldid=prev</id>
		<title>Rasimsen: Created page with &quot;Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern comes under structural patte...&quot;</title>
		<link rel="alternate" type="text/html" href="http://rasimsen.com/index.php?title=Bridge_Design_Pattern&amp;diff=574&amp;oldid=prev"/>
		<updated>2018-08-12T21:52:49Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern comes under structural patte...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern comes under structural pattern as this pattern decouples implementation class and abstract class by providing a bridge structure between them.&lt;br /&gt;
&lt;br /&gt;
This pattern involves an interface which acts as a bridge which makes the functionality of concrete classes independent from interface implementer classes. Both types of classes can be altered structurally without affecting each other.&lt;br /&gt;
&lt;br /&gt;
We are demonstrating use of Bridge pattern via following example in which a circle can be drawn in different colors using same abstract class method but different bridge implementer classes.&lt;br /&gt;
&lt;br /&gt;
=Implementation=&lt;br /&gt;
We have a DrawAPI interface which is acting as a bridge implementer and concrete classes RedCircle, GreenCircle implementing the DrawAPI interface. Shape is an abstract class and will use object of DrawAPI. BridgePatternDemo, our demo class will use Shape class to draw different colored circle.&lt;br /&gt;
&lt;br /&gt;
https://www.tutorialspoint.com/design_pattern/images/bridge_pattern_uml_diagram.jpg&lt;br /&gt;
&lt;br /&gt;
==Step 1-Create bridge implementer interface==&lt;br /&gt;
&lt;br /&gt;
Create bridge implementer interface.&lt;br /&gt;
&lt;br /&gt;
DrawAPI.java&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public interface DrawAPI {&lt;br /&gt;
   public void drawCircle(int radius, int x, int y);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Step 2-Create concrete bridge implementer classes implementing the interface==&lt;br /&gt;
Create concrete bridge implementer classes implementing the DrawAPI interface.&lt;br /&gt;
&lt;br /&gt;
RedCircle.java&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class RedCircle implements DrawAPI {&lt;br /&gt;
   @Override&lt;br /&gt;
   public void drawCircle(int radius, int x, int y) {&lt;br /&gt;
      System.out.println(&amp;quot;Drawing Circle[ color: red, radius: &amp;quot; + radius + &amp;quot;, x: &amp;quot; + x + &amp;quot;, &amp;quot; + y + &amp;quot;]&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
GreenCircle.java&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class GreenCircle implements DrawAPI {&lt;br /&gt;
   @Override&lt;br /&gt;
   public void drawCircle(int radius, int x, int y) {&lt;br /&gt;
      System.out.println(&amp;quot;Drawing Circle[ color: green, radius: &amp;quot; + radius + &amp;quot;, x: &amp;quot; + x + &amp;quot;, &amp;quot; + y + &amp;quot;]&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Step 3-Create an abstract class using the interface.==&lt;br /&gt;
Create an abstract class Shape using the DrawAPI interface.&lt;br /&gt;
&lt;br /&gt;
Shape.java&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public abstract class Shape {&lt;br /&gt;
   protected DrawAPI drawAPI;&lt;br /&gt;
   &lt;br /&gt;
   protected Shape(DrawAPI drawAPI){&lt;br /&gt;
      this.drawAPI = drawAPI;&lt;br /&gt;
   }&lt;br /&gt;
   public abstract void draw();	&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Step 4-Create concrete class implementing the interface==&lt;br /&gt;
Create concrete class implementing the Shape interface.&lt;br /&gt;
&lt;br /&gt;
Circle.java&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class Circle extends Shape {&lt;br /&gt;
   private int x, y, radius;&lt;br /&gt;
&lt;br /&gt;
   public Circle(int x, int y, int radius, DrawAPI drawAPI) {&lt;br /&gt;
      super(drawAPI);&lt;br /&gt;
      this.x = x;  &lt;br /&gt;
      this.y = y;  &lt;br /&gt;
      this.radius = radius;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   public void draw() {&lt;br /&gt;
      drawAPI.drawCircle(radius,x,y);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Step 5-Use the classes to draw different objects==&lt;br /&gt;
Use the Shape and DrawAPI classes to draw different colored circles.&lt;br /&gt;
&lt;br /&gt;
BridgePatternDemo.java&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class BridgePatternDemo {&lt;br /&gt;
   public static void main(String[] args) {&lt;br /&gt;
      Shape redCircle = new Circle(100,100, 10, new RedCircle());&lt;br /&gt;
      Shape greenCircle = new Circle(100,100, 10, new GreenCircle());&lt;br /&gt;
&lt;br /&gt;
      redCircle.draw();&lt;br /&gt;
      greenCircle.draw();&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Step 6==&lt;br /&gt;
Verify the output.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
Drawing Circle[ color: red, radius: 10, x: 100, 100]&lt;br /&gt;
Drawing Circle[  color: green, radius: 10, x: 100, 100]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rasimsen</name></author>
		
	</entry>
</feed>