SlideShare a Scribd company logo
THE BRIDGE PATTERN
PREPARED BY :
NAHIN KUMAR DEY
ROLL : 1507019
MD. AZAHAR ALAM
ROLL : 1507024
MD. FAZLE RASUL
ROLL : 1507029
Course No : CSE- 3120
Course Name : Software Engineering and Information System.
Course Teachers :
Md. Abdus Salim Mollah
Assistant professor,
Dept. of Computer Science and Engineering,
KUET.
Shaikh Akib Shahriyar
Lecturar,
Dept. of Computer Science and Engineering,
KUET.
DESIGN PATTERNS
In software engineering, a design pattern is a general repeatable
solution to a commonly occurring problem in software design.
Design patterns provide a standard terminology and are specific to
particular scenario. Design patterns are mainly of four kinds namely
Creational patterns
Structural patterns
Behavioral patterns
J2EE patterns
THE BRIDGE PATTERN
Bridge pattern is one type of structural pattern and is widely used for
developing software. The bridge uses encapsulation, aggregation, and can
use inheritance to separate responsibilities into different classes.
When a class varies often, the features of object-oriented programming
become very useful because changes to a program's code can be made
easily with minimal prior knowledge about the program. The bridge
pattern is useful when both the class and what it does vary often.
BRIDGE PATTERN CONTINUOUS …..
 CONTEXT :
It is often desirable to decouple an abstraction
from its implementation so that so that the two can vary
independently.
So , often we need to break the serial relation
between a superclass and it’s subordinates to make them
work independently without relating to each other.
BRIDGE PATTERN CONTINUOUS …..
 PROBLEM :
In case, the class and what it does vary too often
the complexity of the system increases drastically and the
system gets way too complicated each time we make a
single modification.
What Design should we use in such cases so that
we can add more classes whenever we need to without
affecting the system complexity ?
BRIDGE PATTERN CONTINUOUS …..
 FORCES :
The design is to separate a class's
interface from its implementation so that we can
vary or replace the implementation without
changing the client code.
BRIDGE PATTERN CONTINUOUS …..
 SOLUTION :
BRIDGE PATTERN CONTINUOUS …..
EXAMPLE :
Step 1: Create bridge implementer interface
DrawApi.java :
Public Interface DrawApi {
public void drawCircle(int radius, int x, int y);
}
Step 2 : Create concrete bridge implementer classes implementing
the DrawApi interface.
RedCircle.java
public class RedCircle implements DrawAPI {
public void drawCircle(int radius, int x, int y) {
System.out.println("Drawing Circle[ color: red, radius: "
+ radius + ", x: " + x + ", " + y + "]");
}
}
GreenCircle.java
public class GreenCircle implements DrawAPI {
@Override
public void drawCircle(int radius, int x, int y) {
System.out.println("Drawing Circle[ color: green,
radius: " + radius + ", x: " + x + ", " + y + "]");
}
}
Step 3 : Create an abstract class Shape using the DrawAPI interface.
Shape.java
public abstract class Shape {
protected DrawAPI drawAPI;
protected Shape(DrawAPI drawAPI){
this.drawAPI = drawAPI;
}
public abstract void draw();
}
Step 4 : Create concrete class implementing the Shape interface.
Circle.java
public class Circle extends Shape {
private int x, y, radius;
public Circle(int x, int y, int radius, DrawAPI drawAPI) {
super(drawAPI);
this.x = x;
this.y = y;
this.radius = radius;
}
public void draw() {
drawAPI.drawCircle(radius,x,y);
}
}
Step 5 : Use the Shape and DrawAPI classes to draw different colored
circles.
BridgePatternDemo.java
public class BridgePatternDemo {
public static void main(String[] args) {
Shape redCircle = new Circle(100,100, 10, new RedCircle());
Shape greenCircle = new Circle(100,100, 10, new GreenCircle());
redCircle.draw();
greenCircle.draw();
}
}
Step 6 : Verify the output.
Drawing Circle[ color: red, radius: 10, x: 100, 100]
Drawing Circle[ color: green, radius: 10, x: 100, 100]
THANK YOU

More Related Content

PDF
Bridge pattern for Dummies
PPS
Bridge Pattern Derek Weeks
PPTX
Bridge Design Pattern
PPT
Aop2007
PPTX
Decorator Pattern
PPT
Bridge pattern
PPTX
Decorator design pattern
ODP
Bridge
Bridge pattern for Dummies
Bridge Pattern Derek Weeks
Bridge Design Pattern
Aop2007
Decorator Pattern
Bridge pattern
Decorator design pattern
Bridge

Similar to Bridge Pattern (20)

DOCX
Design patterns
PPTX
ap assignmnet presentation.pptx
PDF
Design Pattern in Software Engineering
PPTX
Design patterns in Object oriented analysis and design
PPTX
Software Patterns
ODP
Design Patterns Part1
PDF
Design Patterns Java programming language.pdf
PPT
Oops design pattern intro
PPTX
Designpattern
PPTX
How to design an application correctly ?
PPTX
Sofwear deasign and need of design pattern
PPTX
Design Patterns
PPTX
Design pattern
PPTX
bridge-design-pattern.pptx
PPTX
Structural pattern 3
PPTX
Design pattern and their application
PPTX
Design Pattern - Introduction
PPTX
UNIT IV DESIGN PATTERNS.pptx
PPT
Design Patterns
PDF
UML Design Class Diagrams (2014)
Design patterns
ap assignmnet presentation.pptx
Design Pattern in Software Engineering
Design patterns in Object oriented analysis and design
Software Patterns
Design Patterns Part1
Design Patterns Java programming language.pdf
Oops design pattern intro
Designpattern
How to design an application correctly ?
Sofwear deasign and need of design pattern
Design Patterns
Design pattern
bridge-design-pattern.pptx
Structural pattern 3
Design pattern and their application
Design Pattern - Introduction
UNIT IV DESIGN PATTERNS.pptx
Design Patterns
UML Design Class Diagrams (2014)
Ad

Recently uploaded (20)

PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Trump Administration's workforce development strategy
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
IGGE1 Understanding the Self1234567891011
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Classroom Observation Tools for Teachers
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Weekly quiz Compilation Jan -July 25.pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Orientation - ARALprogram of Deped to the Parents.pptx
What if we spent less time fighting change, and more time building what’s rig...
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Trump Administration's workforce development strategy
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Final Presentation General Medicine 03-08-2024.pptx
IGGE1 Understanding the Self1234567891011
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Hazard Identification & Risk Assessment .pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Paper A Mock Exam 9_ Attempt review.pdf.
LDMMIA Reiki Yoga Finals Review Spring Summer
Classroom Observation Tools for Teachers
Ad

Bridge Pattern

  • 1. THE BRIDGE PATTERN PREPARED BY : NAHIN KUMAR DEY ROLL : 1507019 MD. AZAHAR ALAM ROLL : 1507024 MD. FAZLE RASUL ROLL : 1507029
  • 2. Course No : CSE- 3120 Course Name : Software Engineering and Information System. Course Teachers : Md. Abdus Salim Mollah Assistant professor, Dept. of Computer Science and Engineering, KUET. Shaikh Akib Shahriyar Lecturar, Dept. of Computer Science and Engineering, KUET.
  • 3. DESIGN PATTERNS In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. Design patterns provide a standard terminology and are specific to particular scenario. Design patterns are mainly of four kinds namely Creational patterns Structural patterns Behavioral patterns J2EE patterns
  • 4. THE BRIDGE PATTERN Bridge pattern is one type of structural pattern and is widely used for developing software. The bridge uses encapsulation, aggregation, and can use inheritance to separate responsibilities into different classes. When a class varies often, the features of object-oriented programming become very useful because changes to a program's code can be made easily with minimal prior knowledge about the program. The bridge pattern is useful when both the class and what it does vary often.
  • 5. BRIDGE PATTERN CONTINUOUS …..  CONTEXT : It is often desirable to decouple an abstraction from its implementation so that so that the two can vary independently. So , often we need to break the serial relation between a superclass and it’s subordinates to make them work independently without relating to each other.
  • 6. BRIDGE PATTERN CONTINUOUS …..  PROBLEM : In case, the class and what it does vary too often the complexity of the system increases drastically and the system gets way too complicated each time we make a single modification. What Design should we use in such cases so that we can add more classes whenever we need to without affecting the system complexity ?
  • 7. BRIDGE PATTERN CONTINUOUS …..  FORCES : The design is to separate a class's interface from its implementation so that we can vary or replace the implementation without changing the client code.
  • 8. BRIDGE PATTERN CONTINUOUS …..  SOLUTION :
  • 9. BRIDGE PATTERN CONTINUOUS ….. EXAMPLE :
  • 10. Step 1: Create bridge implementer interface DrawApi.java : Public Interface DrawApi { public void drawCircle(int radius, int x, int y); }
  • 11. Step 2 : Create concrete bridge implementer classes implementing the DrawApi interface. RedCircle.java public class RedCircle implements DrawAPI { public void drawCircle(int radius, int x, int y) { System.out.println("Drawing Circle[ color: red, radius: " + radius + ", x: " + x + ", " + y + "]"); } }
  • 12. GreenCircle.java public class GreenCircle implements DrawAPI { @Override public void drawCircle(int radius, int x, int y) { System.out.println("Drawing Circle[ color: green, radius: " + radius + ", x: " + x + ", " + y + "]"); } }
  • 13. Step 3 : Create an abstract class Shape using the DrawAPI interface. Shape.java public abstract class Shape { protected DrawAPI drawAPI; protected Shape(DrawAPI drawAPI){ this.drawAPI = drawAPI; } public abstract void draw(); }
  • 14. Step 4 : Create concrete class implementing the Shape interface. Circle.java public class Circle extends Shape { private int x, y, radius; public Circle(int x, int y, int radius, DrawAPI drawAPI) { super(drawAPI); this.x = x; this.y = y; this.radius = radius; } public void draw() { drawAPI.drawCircle(radius,x,y); } }
  • 15. Step 5 : Use the Shape and DrawAPI classes to draw different colored circles. BridgePatternDemo.java public class BridgePatternDemo { public static void main(String[] args) { Shape redCircle = new Circle(100,100, 10, new RedCircle()); Shape greenCircle = new Circle(100,100, 10, new GreenCircle()); redCircle.draw(); greenCircle.draw(); } }
  • 16. Step 6 : Verify the output. Drawing Circle[ color: red, radius: 10, x: 100, 100] Drawing Circle[ color: green, radius: 10, x: 100, 100]