Skip to content

Commit 6d83ceb

Browse files
committed
Update README.md
1 parent 015b418 commit 6d83ceb

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

Diff for: bridge/README.md

+19-10
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,34 @@ tags:
99
---
1010

1111
## Also known as
12+
1213
Handle/Body
1314

1415
## Intent
16+
1517
Decouple an abstraction from its implementation so that the two can vary independently.
1618

1719
## Explanation
1820

1921
Real world example
2022

21-
> Consider you have a weapon with different enchantments and you are supposed to allow mixing different weapons with different enchantments. What would you do? Create multiple copies of each of the weapons for each of the enchantments or would you just create separate enchantment and set it for the weapon as needed? Bridge pattern allows you to do the second.
23+
> Consider you have a weapon with different enchantments, and you are supposed to allow mixing
24+
> different weapons with different enchantments. What would you do? Create multiple copies of each
25+
> of the weapons for each of the enchantments or would you just create separate enchantment and set
26+
> it for the weapon as needed? Bridge pattern allows you to do the second.
2227
2328
In Plain Words
2429

25-
> Bridge pattern is about preferring composition over inheritance. Implementation details are pushed from a hierarchy to another object with a separate hierarchy.
30+
> Bridge pattern is about preferring composition over inheritance. Implementation details are pushed
31+
> from a hierarchy to another object with a separate hierarchy.
2632
2733
Wikipedia says
2834

2935
> The bridge pattern is a design pattern used in software engineering that is meant to "decouple an abstraction from its implementation so that the two can vary independently"
3036
3137
**Programmatic Example**
3238

33-
Translating our weapon example from above. Here we have the `Weapon` hierarchy
39+
Translating our weapon example from above. Here we have the `Weapon` hierarchy:
3440

3541
```java
3642
public interface Weapon {
@@ -105,7 +111,7 @@ public class Hammer implements Weapon {
105111
}
106112
```
107113

108-
And the separate enchantment hierarchy
114+
Here's the separate enchantment hierarchy:
109115

110116
```java
111117
public interface Enchantment {
@@ -151,7 +157,7 @@ public class SoulEatingEnchantment implements Enchantment {
151157
}
152158
```
153159

154-
And both the hierarchies in action
160+
Here are both hierarchies in action:
155161

156162
```java
157163
var enchantedSword = new Sword(new SoulEatingEnchantment());
@@ -178,18 +184,21 @@ hammer.unwield();
178184
```
179185

180186
## Class diagram
187+
181188
![alt text](./etc/bridge.urm.png "Bridge class diagram")
182189

183190
## Applicability
191+
184192
Use the Bridge pattern when
185193

186-
* you want to avoid a permanent binding between an abstraction and its implementation. This might be the case, for example, when the implementation must be selected or switched at run-time.
187-
* both the abstractions and their implementations should be extensible by subclassing. In this case, the Bridge pattern lets you combine the different abstractions and implementations and extend them independently
188-
* changes in the implementation of an abstraction should have no impact on clients; that is, their code should not have to be recompiled.
189-
* you have a proliferation of classes. Such a class hierarchy indicates the need for splitting an object into two parts. Rumbaugh uses the term "nested generalizations" to refer to such class hierarchies
190-
* you want to share an implementation among multiple objects (perhaps using reference counting), and this fact should be hidden from the client. A simple example is Coplien's String class, in which multiple objects can share the same string representation.
194+
* You want to avoid a permanent binding between an abstraction and its implementation. This might be the case, for example, when the implementation must be selected or switched at run-time.
195+
* Both the abstractions and their implementations should be extensible by subclassing. In this case, the Bridge pattern lets you combine the different abstractions and implementations and extend them independently.
196+
* Changes in the implementation of an abstraction should have no impact on clients; that is, their code should not have to be recompiled.
197+
* You have a proliferation of classes. Such a class hierarchy indicates the need for splitting an object into two parts. Rumbaugh uses the term "nested generalizations" to refer to such class hierarchies.
198+
* You want to share an implementation among multiple objects (perhaps using reference counting), and this fact should be hidden from the client. A simple example is Coplien's String class, in which multiple objects can share the same string representation.
191199

192200
## Tutorial
201+
193202
* [Bridge Pattern Tutorial](https://www.journaldev.com/1491/bridge-design-pattern-java)
194203

195204
## Credits

0 commit comments

Comments
 (0)