Skip to content

Commit 755af2b

Browse files
author
Oktawian Chojnacki
committed
Xcode 6.3 beta and Swift 1.2 update + generate.
1 parent efabcae commit 755af2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+522
-523
lines changed

Design-Patterns.playground.zip

209 Bytes
Binary file not shown.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<p>Shorter but oh-so-ugly alternative:</p>
14+
<h2 id="-factory-method">🏭 Factory Method</h2>
15+
<p>The factory pattern is used to replace class constructors, abstracting the process of object generation so that the type of the object instantiated can be determined at run-time.</p>
16+
<p><strong>Example:</strong></p>
1517

1618
</section>
1719
</div>

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-factory-method">🏭 Factory Method</h2>
15-
<p>The factory pattern is used to replace class constructors, abstracting the process of object generation so that the type of the object instantiated can be determined at run-time.</p>
16-
<p><strong>Example:</strong></p>
14+
<p><strong>Usage:</strong></p>
1715

1816
</section>
1917
</div>

Design-Patterns.playground/Documentation/section-49.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-
<p><strong>Usage:</strong></p>
14+
<h2 id="-prototype">🃏 Prototype</h2>
15+
<p>The prototype pattern is used to instantiate a new object by copying all of the properties of an existing object, creating an independent clone.
16+
This practise is particularly useful when the construction of a new object is inefficient.</p>
17+
<p><strong>Example:</strong></p>
1518

1619
</section>
1720
</div>

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-prototype">🃏 Prototype</h2>
15-
<p>The prototype pattern is used to instantiate a new object by copying all of the properties of an existing object, creating an independent clone.
16-
This practise is particularly useful when the construction of a new object is inefficient.</p>
17-
<p><strong>Example:</strong></p>
14+
<p><strong>Usage:</strong></p>
1815

1916
</section>
2017
</div>

Design-Patterns.playground/Documentation/section-53.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-
<p><strong>Usage:</strong></p>
14+
<h2 id="-singleton">💍 Singleton</h2>
15+
<p>The singleton pattern ensures that only one object of a particular class is ever created.
16+
All further references to objects of the singleton class refer to the same underlying instance.</p>
17+
<p><strong>Example:</strong></p>
1518

1619
</section>
1720
</div>

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-singleton">💍 Singleton</h2>
15-
<p>The singleton pattern ensures that only one object of a particular class is ever created.
16-
All further references to objects of the singleton class refer to the same underlying instance.</p>
17-
<p><strong>Example:</strong></p>
14+
<p><strong>Usage:</strong></p>
1815

1916
</section>
2017
</div>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<p><strong>Usage:</strong></p>
14+
<h1 id="structural">Structural</h1>
15+
<blockquote>
16+
<p>In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities.</p>
17+
<p><strong>Source:</strong> <a href="http://en.wikipedia.org/wiki/Structural_pattern">wikipedia.org</a></p>
18+
</blockquote>
19+
<h2 id="-adapter">🔌 Adapter</h2>
20+
<p>The adapter pattern is used to provide a link between two otherwise incompatible types by wrapping the &quot;adaptee&quot; with a class that supports the interface required by the client.</p>
21+
<p><strong>Example:</strong></p>
1522

1623
</section>
1724
</div>

Design-Patterns.playground/Documentation/section-59.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-
<h1 id="structural">Structural</h1>
15-
<blockquote>
16-
<p>In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities.</p>
17-
<p><strong>Source:</strong> <a href="http://en.wikipedia.org/wiki/Structural_pattern">wikipedia.org</a></p>
18-
</blockquote>
19-
<h2 id="-adapter">🔌 Adapter</h2>
20-
<p>The adapter pattern is used to provide a link between two otherwise incompatible types by wrapping the &quot;adaptee&quot; with a class that supports the interface required by the client.</p>
21-
<p><strong>Example:</strong></p>
14+
<p><strong>Usage:</strong></p>
2215

2316
</section>
2417
</div>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<p><strong>Usage:</strong></p>
14+
<h2 id="-bridge">🌉 Bridge</h2>
15+
<p>The bridge pattern is used to separate the abstract elements of a class from the implementation details, providing the means to replace the implementation details without modifying the abstraction.</p>
16+
<p><strong>Example:</strong></p>
1517

1618
</section>
1719
</div>

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-bridge">🌉 Bridge</h2>
15-
<p>The bridge pattern is used to separate the abstract elements of a class from the implementation details, providing the means to replace the implementation details without modifying the abstraction.</p>
16-
<p><strong>Example:</strong></p>
14+
<p><strong>Usage</strong></p>
1715

1816
</section>
1917
</div>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<p><strong>Usage</strong></p>
14+
<h2 id="-composite">🌿 Composite</h2>
15+
<p>The composite pattern is used to create hierarchical, recursive tree structures of related objects where any element of the structure may be accessed and utilised in a standard manner.</p>
16+
<p><strong>Example:</strong></p>
1517

1618
</section>
1719
</div>

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-composite">🌿 Composite</h2>
15-
<p>The composite pattern is used to create hierarchical, recursive tree structures of related objects where any element of the structure may be accessed and utilised in a standard manner.</p>
16-
<p><strong>Example:</strong></p>
14+
<p><strong>Usage:</strong></p>
1715

1816
</section>
1917
</div>

Design-Patterns.playground/Documentation/section-69.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-
<p><strong>Usage:</strong></p>
14+
<h2 id="-decorator">🍧 Decorator</h2>
15+
<p>The decorator pattern is used to extend or alter the functionality of objects at run- time by wrapping them in an object of a decorator class.
16+
This provides a flexible alternative to using inheritance to modify behaviour.</p>
17+
<p><strong>Example:</strong></p>
1518

1619
</section>
1720
</div>

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-decorator">🍧 Decorator</h2>
15-
<p>The decorator pattern is used to extend or alter the functionality of objects at run- time by wrapping them in an object of a decorator class.
16-
This provides a flexible alternative to using inheritance to modify behaviour.</p>
17-
<p><strong>Example:</strong></p>
14+
<p><strong>Usage:</strong></p>
1815

1916
</section>
2017
</div>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<p><strong>Usage:</strong></p>
14+
<h2 id="-fa-ade">🎁 Façade</h2>
15+
<p>The facade pattern is used to define a simplified interface to a more complex subsystem.</p>
16+
<p><strong>Example:</strong></p>
1517

1618
</section>
1719
</div>

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-fa-ade">🎁 Façade</h2>
15-
<p>The facade pattern is used to define a simplified interface to a more complex subsystem.</p>
16-
<p><strong>Example:</strong></p>
14+
<p><strong>Usage:</strong></p>
1715

1816
</section>
1917
</div>

Design-Patterns.playground/Documentation/section-77.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-
<p><strong>Usage:</strong></p>
14+
<h2 id="-protection-proxy">☔ Protection Proxy</h2>
15+
<p>The proxy pattern is used to provide a surrogate or placeholder object, which references an underlying object.
16+
Protection proxy is restricting access.</p>
17+
<p><strong>Example:</strong></p>
1518

1619
</section>
1720
</div>

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-protection-proxy">☔ Protection Proxy</h2>
15-
<p>The proxy pattern is used to provide a surrogate or placeholder object, which references an underlying object.
16-
Protection proxy is restricting access.</p>
17-
<p><strong>Example:</strong></p>
14+
<p><strong>Usage:</strong></p>
1815

1916
</section>
2017
</div>

Design-Patterns.playground/Documentation/section-81.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-
<p><strong>Usage:</strong></p>
14+
<h2 id="-virtual-proxy">🍬 Virtual Proxy</h2>
15+
<p>The proxy pattern is used to provide a surrogate or placeholder object, which references an underlying object.
16+
Virtual proxy is used for loading object on demand.</p>
17+
<p><strong>Example:</strong></p>
1518

1619
</section>
1720
</div>

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="-virtual-proxy">🍬 Virtual Proxy</h2>
15-
<p>The proxy pattern is used to provide a surrogate or placeholder object, which references an underlying object.
16-
Virtual proxy is used for loading object on demand.</p>
17-
<p><strong>Example:</strong></p>
14+
<p><strong>Usage:</strong></p>
1815

1916
</section>
2017
</div>

Design-Patterns.playground/Documentation/section-85.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-
<p><strong>Usage:</strong></p>
14+
<h1 id="info">Info</h1>
15+
<p>🍺 Playground generated with: <a href="https://github.com/jas/playground">playground</a> by <a href="http://twitter.com/jasonsandmeyer">@jasonsandmeyer</a></p>
16+
<p>📖 Descriptions from: <a href="http://www.blackwasp.co.uk/GangOfFour.aspx">Gang of Four Design Patterns Reference Sheet</a></p>
17+
<p>🚀 How to generate playground (+zip) from this README: <a href="https://github.com/ochococo/Design-Patterns-In-Swift/blob/master/GENERATE.md">GENERATE.md</a></p>
1518

1619
</section>
1720
</div>

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

Lines changed: 0 additions & 22 deletions
This file was deleted.

Design-Patterns.playground/contents.xcplayground

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,5 @@
173173
</code>
174174
<documentation relative-path="section-85.html">
175175
</documentation>
176-
<code source-file-name="section-86.swift">
177-
</code>
178-
<documentation relative-path="section-87.html">
179-
</documentation>
180176
</sections>
181177
</playground>

Design-Patterns.playground/section-18.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class GameState {
1616
}
1717

1818
func restoreFromMemento(memento: Memento) {
19-
chapter = memento[DPMementoKeyChapter] as String? ?? "n/a"
20-
weapon = memento[DPMementoKeyWeapon] as String? ?? "n/a"
19+
chapter = memento[DPMementoKeyChapter] as? String ?? "n/a"
20+
weapon = memento[DPMementoKeyWeapon] as? String ?? "n/a"
2121
}
2222
}
2323

@@ -34,6 +34,6 @@ class CheckPoint {
3434
class func restorePreviousState(keyName: String = DPMementoGameState) -> Memento {
3535
let defaults = NSUserDefaults.standardUserDefaults()
3636

37-
return defaults.objectForKey(keyName) as Memento! ?? Memento()
37+
return defaults.objectForKey(keyName) as? Memento ?? Memento()
3838
}
3939
}

Design-Patterns.playground/section-22.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ class TestChambers {
1919

2020
class Observer : PropertyObserver {
2121
func willChangePropertyName(propertyName: String, newPropertyValue: AnyObject?) {
22-
if newPropertyValue as Int? == 1 {
22+
if newPropertyValue as? Int == 1 {
2323
println("Okay. Look. We both said a lot of things that you're going to regret.")
2424
}
2525
}
2626

2727
func didChangePropertyName(propertyName: String, oldPropertyValue: AnyObject?) {
28-
if oldPropertyValue as Int? == 0 {
28+
if oldPropertyValue as? Int == 0 {
2929
println("Sorry about the mess. I've really let the place go since you killed me.")
3030
}
3131
}
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
protocol ThreeDimensions {
2-
var x: Double? {get}
3-
var y: Double? {get}
4-
var z: Double? {get}
5-
}
1+
class DeathStarBuilder {
62

7-
class Point : ThreeDimensions {
83
var x: Double?
94
var y: Double?
105
var z: Double?
116

12-
typealias PointBuilderClosure = (Point) -> ()
7+
typealias BuilderClosure = (DeathStarBuilder) -> ()
138

14-
init(buildClosure: PointBuilderClosure) {
9+
init(buildClosure: BuilderClosure) {
1510
buildClosure(self)
1611
}
1712
}
13+
14+
struct DeathStar {
15+
16+
let x: Double
17+
let y: Double
18+
let z: Double
19+
20+
init?(builder: DeathStarBuilder) {
21+
22+
if let x = builder.x, y = builder.y, z = builder.z {
23+
self.x = x
24+
self.y = y
25+
self.z = z
26+
} else {
27+
return nil
28+
}
29+
}
30+
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
let fancyPoint = Point { point in
2-
point.x = 0.1
3-
point.y = 0.2
4-
point.z = 0.3
1+
let empire = DeathStarBuilder { builder in
2+
builder.x = 0.1
3+
builder.y = 0.2
4+
builder.z = 0.3
55
}
66

7-
fancyPoint.x
8-
fancyPoint.y
9-
fancyPoint.z
7+
let deathStar = DeathStar(builder:empire)

0 commit comments

Comments
 (0)