Skip to content

Commit 09b1269

Browse files
committed
+generation
1 parent d4131a9 commit 09b1269

25 files changed

+292
-211
lines changed

Design-Patterns.playground.zip

1.5 KB
Binary file not shown.

Design-Patterns.playground/Documentation/section-35.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-bridge">🚧 Bridge</h2>
15-
<h2 id="-decorator">🍧 Decorator</h2>
14+
<h2 id="-bridge">🌉 Bridge</h2>
1615

1716
</section>
1817
</div>

Design-Patterns.playground/Documentation/section-37.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<p><strong>Usage:</strong></p>
14+
<p><strong>Usage</strong></p>
1515

1616
</section>
1717
</div>

Design-Patterns.playground/Documentation/section-39.html

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-proxy">🚧 Proxy</h2>
15-
<h1 id="behavioral">Behavioral</h1>
16-
<blockquote>
17-
<p>In software engineering, behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.</p>
18-
<p><strong>Source:</strong> <a href="http://en.wikipedia.org/wiki/Behavioral_pattern">wikipedia.org</a></p>
19-
</blockquote>
20-
<h2 id="-chain-of-responsibility">🚧 Chain Of Responsibility</h2>
21-
<h2 id="-command">👫 Command</h2>
14+
<h2 id="-decorator">🍧 Decorator</h2>
2215

2316
</section>
2417
</div>

Design-Patterns.playground/Documentation/section-43.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-iterator">🚧 Iterator</h2>
15-
<h2 id="-mediator">🚧 Mediator</h2>
16-
<h2 id="-memento">🚧 Memento</h2>
17-
<h2 id="-observer">📩 Observer</h2>
14+
<h2 id="-proxy">🚧 Proxy</h2>
15+
<h1 id="behavioral">Behavioral</h1>
16+
<blockquote>
17+
<p>In software engineering, behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.</p>
18+
<p><strong>Source:</strong> <a href="http://en.wikipedia.org/wiki/Behavioral_pattern">wikipedia.org</a></p>
19+
</blockquote>
20+
<h2 id="-chain-of-responsibility">🚧 Chain Of Responsibility</h2>
21+
<h2 id="-command">👫 Command</h2>
1822

1923
</section>
2024
</div>

Design-Patterns.playground/Documentation/section-47.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-state">🐉 State</h2>
14+
<h2 id="-iterator">🚧 Iterator</h2>
15+
<h2 id="-mediator">🚧 Mediator</h2>
16+
<h2 id="-memento">🚧 Memento</h2>
17+
<h2 id="-observer">📩 Observer</h2>
1518

1619
</section>
1720
</div>

Design-Patterns.playground/Documentation/section-51.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-strategy">💡 Strategy</h2>
14+
<h2 id="-state">🐉 State</h2>
1515

1616
</section>
1717
</div>

Design-Patterns.playground/Documentation/section-55.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-visitor">🏃 Visitor</h2>
14+
<h2 id="-strategy">💡 Strategy</h2>
1515

1616
</section>
1717
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Section 60</title>
6+
<meta id="xcode-display" name="xcode-display" content="render">
7+
<meta name="apple-mobile-web-app-capable" content="yes">
8+
<meta name="viewport" content="width=device-width, maximum-scale=1.0">
9+
<link rel="stylesheet" type="text/css" href="stylesheet.css">
10+
</head>
11+
<body>
12+
<div class="content-wrapper">
13+
<section class="section">
14+
<h2 id="-visitor">🏃 Visitor</h2>
15+
16+
</section>
17+
</div>
18+
</body>
19+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Section 62</title>
6+
<meta id="xcode-display" name="xcode-display" content="render">
7+
<meta name="apple-mobile-web-app-capable" content="yes">
8+
<meta name="viewport" content="width=device-width, maximum-scale=1.0">
9+
<link rel="stylesheet" type="text/css" href="stylesheet.css">
10+
</head>
11+
<body>
12+
<div class="content-wrapper">
13+
<section class="section">
14+
<p><strong>Usage:</strong></p>
15+
16+
</section>
17+
</div>
18+
</body>
19+
</html>

Design-Patterns.playground/contents.xcplayground

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,13 @@
119119
</documentation>
120120
<code source-file-name="section-58.swift">
121121
</code>
122+
<documentation relative-path="section-59.html">
123+
</documentation>
124+
<code source-file-name="section-60.swift">
125+
</code>
126+
<documentation relative-path="section-61.html">
127+
</documentation>
128+
<code source-file-name="section-62.swift">
129+
</code>
122130
</sections>
123131
</playground>
Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,31 @@
1-
protocol Coffee {
2-
func getCost() -> Double
3-
func getIngredients() -> String
1+
protocol Switch {
2+
var appliance: Appliance {get set}
3+
func turnOn()
44
}
55

6-
class SimpleCoffee: Coffee {
7-
func getCost() -> Double {
8-
return 1.0
9-
}
10-
func getIngredients() -> String {
11-
return "Coffee"
12-
}
6+
protocol Appliance {
7+
func run()
138
}
149

15-
class CoffeeDecorator: Coffee {
16-
private let decoratedCoffee: Coffee
17-
private let ingredientSeparator: String = ", "
18-
19-
required init(decoratedCoffee: Coffee) {
20-
self.decoratedCoffee = decoratedCoffee
21-
}
22-
func getCost() -> Double {
23-
return decoratedCoffee.getCost()
10+
class RemoteControl: Switch {
11+
var appliance: Appliance
12+
func turnOn() {
13+
self.appliance.run()
2414
}
25-
func getIngredients() -> String {
26-
return decoratedCoffee.getIngredients()
15+
16+
init(appliance: Appliance) {
17+
self.appliance = appliance
2718
}
2819
}
2920

30-
class Milk: CoffeeDecorator {
31-
required init(decoratedCoffee: Coffee) {
32-
super.init(decoratedCoffee: decoratedCoffee)
33-
}
34-
override func getCost() -> Double {
35-
return super.getCost() + 0.5
36-
}
37-
override func getIngredients() -> String {
38-
return super.getIngredients() + ingredientSeparator + "Milk"
21+
class TV: Appliance {
22+
func run() {
23+
println("tv turned on");
3924
}
4025
}
4126

42-
class WhipCoffee: CoffeeDecorator {
43-
required init(decoratedCoffee: Coffee) {
44-
super.init(decoratedCoffee: decoratedCoffee)
45-
}
46-
override func getCost() -> Double {
47-
return super.getCost() + 0.7
48-
}
49-
override func getIngredients() -> String {
50-
return super.getIngredients() + ingredientSeparator + "Whip"
27+
class VacuumCleaner: Appliance {
28+
func run() {
29+
println("vacuum cleaner turned on")
5130
}
5231
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
var someCoffee: Coffee = SimpleCoffee()
2-
println("Cost : \(someCoffee.getCost()); Ingredients: \(someCoffee.getIngredients())")
3-
someCoffee = Milk(decoratedCoffee: someCoffee)
4-
println("Cost : \(someCoffee.getCost()); Ingredients: \(someCoffee.getIngredients())")
5-
someCoffee = WhipCoffee(decoratedCoffee: someCoffee)
6-
println("Cost : \(someCoffee.getCost()); Ingredients: \(someCoffee.getIngredients())")
1+
var tvRemoteControl = RemoteControl(appliance: TV())
2+
tvRemoteControl.turnOn()
3+
4+
var fancyVacuumCleanerRemoteControl = RemoteControl(appliance: VacuumCleaner())
5+
fancyVacuumCleanerRemoteControl.turnOn()
Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,52 @@
1-
protocol FileOperationCommand {
2-
init(file: String)
3-
func execute()
1+
protocol Coffee {
2+
func getCost() -> Double
3+
func getIngredients() -> String
44
}
55

6-
class FileMoveCommand : FileOperationCommand {
7-
let file:String
8-
required init(file: String) {
9-
self.file = file
6+
class SimpleCoffee: Coffee {
7+
func getCost() -> Double {
8+
return 1.0
109
}
11-
12-
func execute() {
13-
print("\(file) moved")
10+
func getIngredients() -> String {
11+
return "Coffee"
1412
}
1513
}
1614

17-
class FileDeleteCommand : FileOperationCommand {
18-
let file:String
19-
required init(file: String) {
20-
self.file = file
15+
class CoffeeDecorator: Coffee {
16+
private let decoratedCoffee: Coffee
17+
private let ingredientSeparator: String = ", "
18+
19+
required init(decoratedCoffee: Coffee) {
20+
self.decoratedCoffee = decoratedCoffee
21+
}
22+
func getCost() -> Double {
23+
return decoratedCoffee.getCost()
2124
}
22-
23-
func execute() {
24-
print("\(file) deleted")
25+
func getIngredients() -> String {
26+
return decoratedCoffee.getIngredients()
2527
}
2628
}
2729

28-
class FileManager {
29-
let deleteCommand: FileOperationCommand
30-
let moveCommand: FileOperationCommand
31-
32-
init(deleteCommand: FileDeleteCommand, moveCommand: FileMoveCommand) {
33-
self.deleteCommand = deleteCommand
34-
self.moveCommand = moveCommand
35-
}
36-
37-
func delete () {
38-
deleteCommand.execute()
39-
}
40-
41-
func move () {
42-
moveCommand.execute()
30+
class Milk: CoffeeDecorator {
31+
required init(decoratedCoffee: Coffee) {
32+
super.init(decoratedCoffee: decoratedCoffee)
33+
}
34+
override func getCost() -> Double {
35+
return super.getCost() + 0.5
36+
}
37+
override func getIngredients() -> String {
38+
return super.getIngredients() + ingredientSeparator + "Milk"
39+
}
40+
}
41+
42+
class WhipCoffee: CoffeeDecorator {
43+
required init(decoratedCoffee: Coffee) {
44+
super.init(decoratedCoffee: decoratedCoffee)
45+
}
46+
override func getCost() -> Double {
47+
return super.getCost() + 0.7
48+
}
49+
override func getIngredients() -> String {
50+
return super.getIngredients() + ingredientSeparator + "Whip"
4351
}
4452
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
let deleteCommand = FileDeleteCommand(file: "/path/to/testfile")
2-
let moveCommand = FileMoveCommand(file: "/path/to/testfile")
3-
let fileManager = FileManager(deleteCommand:deleteCommand , moveCommand: moveCommand)
4-
5-
fileManager.delete()
6-
fileManager.move()
1+
var someCoffee: Coffee = SimpleCoffee()
2+
println("Cost : \(someCoffee.getCost()); Ingredients: \(someCoffee.getIngredients())")
3+
someCoffee = Milk(decoratedCoffee: someCoffee)
4+
println("Cost : \(someCoffee.getCost()); Ingredients: \(someCoffee.getIngredients())")
5+
someCoffee = WhipCoffee(decoratedCoffee: someCoffee)
6+
println("Cost : \(someCoffee.getCost()); Ingredients: \(someCoffee.getIngredients())")
Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
1-
class StepCounter {
2-
var totalSteps: Int = 0 {
3-
willSet(newTotalSteps) {
4-
println("About to set totalSteps to \(newTotalSteps)")
5-
}
6-
didSet {
7-
if totalSteps > oldValue {
8-
println("Added \(totalSteps - oldValue) steps")
9-
}
10-
}
1+
protocol FileOperationCommand {
2+
init(file: String)
3+
func execute()
4+
}
5+
6+
class FileMoveCommand : FileOperationCommand {
7+
let file:String
8+
required init(file: String) {
9+
self.file = file
10+
}
11+
12+
func execute() {
13+
print("\(file) moved")
14+
}
15+
}
16+
17+
class FileDeleteCommand : FileOperationCommand {
18+
let file:String
19+
required init(file: String) {
20+
self.file = file
21+
}
22+
23+
func execute() {
24+
print("\(file) deleted")
25+
}
26+
}
27+
28+
class FileManager {
29+
let deleteCommand: FileOperationCommand
30+
let moveCommand: FileOperationCommand
31+
32+
init(deleteCommand: FileDeleteCommand, moveCommand: FileMoveCommand) {
33+
self.deleteCommand = deleteCommand
34+
self.moveCommand = moveCommand
35+
}
36+
37+
func delete () {
38+
deleteCommand.execute()
39+
}
40+
41+
func move () {
42+
moveCommand.execute()
1143
}
1244
}

0 commit comments

Comments
 (0)