Skip to content

Commit d4131a9

Browse files
committed
Merge branch 'tomkowz-master'
* tomkowz-master: Added Bridge design pattern
2 parents 9d5e563 + 8954547 commit d4131a9

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

README.markdown

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,50 @@ tuple.y
325325
tuple.z
326326
```
327327

328-
##🚧 Bridge
328+
##🌉 Bridge
329+
```swift
330+
protocol Switch {
331+
var appliance: Appliance {get set}
332+
func turnOn()
333+
}
334+
335+
protocol Appliance {
336+
func run()
337+
}
338+
339+
class RemoteControl: Switch {
340+
var appliance: Appliance
341+
func turnOn() {
342+
self.appliance.run()
343+
}
344+
345+
init(appliance: Appliance) {
346+
self.appliance = appliance
347+
}
348+
}
349+
350+
class TV: Appliance {
351+
func run() {
352+
println("tv turned on");
353+
}
354+
}
355+
356+
class VacuumCleaner: Appliance {
357+
func run() {
358+
println("vacuum cleaner turned on")
359+
}
360+
}
361+
```
362+
363+
**Usage**
364+
```swift
365+
var tvRemoteControl = RemoteControl(appliance: TV())
366+
tvRemoteControl.turnOn()
367+
368+
var fancyVacuumCleanerRemoteControl = RemoteControl(appliance: VacuumCleaner())
369+
fancyVacuumCleanerRemoteControl.turnOn()
370+
```
371+
329372
##🍧 Decorator
330373

331374
```swift
@@ -393,6 +436,7 @@ someCoffee = WhipCoffee(decoratedCoffee: someCoffee)
393436
println("Cost : \(someCoffee.getCost()); Ingredients: \(someCoffee.getIngredients())")
394437
```
395438

439+
396440
##🚧 Proxy
397441

398442
#Behavioral

0 commit comments

Comments
 (0)