Skip to content

Commit ab5dc34

Browse files
author
Sebastian Boldt
committed
Implemented Bridge Pattern
1 parent c19716e commit ab5dc34

File tree

16 files changed

+51
-3
lines changed

16 files changed

+51
-3
lines changed

GOFSwift.playground/Pages/Command.xcplaygroundpage/Contents.swift renamed to Behavioral.playground/Pages/Command.xcplaygroundpage/Contents.swift

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
//: [Previous](@previous)
22

3+
/*:
4+
## Command Pattern
5+
6+
Wrapping functions into object with generalized interface
7+
*/
8+
39
import Foundation
410

511
protocol DoorCommand {

GOFSwift.playground/contents.xcplayground renamed to Behavioral.playground/contents.xcplayground

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<playground version='6.0' target-platform='ios' display-mode='rendered'>
2+
<playground version='6.0' target-platform='ios' display-mode='raw'>
33
<pages>
44
<page name='Intro'/>
55
<page name='Chain of Responsibility '/>

GOFSwift.xcworkspace/contents.xcworkspacedata

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Inspired by: https://github.com/ochococo/Design-Patterns-In-Swift
2727
##Structural
2828

2929
* Adapter
30-
* Bridge
30+
* Bridge
3131
* Composite
3232
* Decorator
3333
* Facade
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//: [Previous](@previous)
2+
3+
import Foundation
4+
5+
protocol Device {
6+
func run()
7+
}
8+
9+
class RemoteControl {
10+
var device: Device
11+
12+
func turnOn() {
13+
self.device.run()
14+
}
15+
16+
init(device: Device) {
17+
self.device = device
18+
}
19+
}
20+
21+
class TV: Device {
22+
func run() {
23+
print("TV is running now")
24+
}
25+
}
26+
27+
class Vacuum: Device {
28+
func run() {
29+
print("Vacuum is running now")
30+
}
31+
}
32+
33+
let control = RemoteControl(device: Vacuum())
34+
control.turnOn()
35+
36+
37+
//: [Next](@next)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<playground version='6.0' target-platform='ios'/>

0 commit comments

Comments
 (0)