Skip to content

Commit 9d3f8eb

Browse files
committed
Façade (draft)
1 parent 9ee4f65 commit 9d3f8eb

11 files changed

+169
-45
lines changed

Design-Patterns.playground.zip

1.75 KB
Binary file not shown.

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,7 @@ <h1 id="structural">Structural</h1>
1717
<p><strong>Source:</strong> <a href="http://en.wikipedia.org/wiki/Structural_pattern">wikipedia.org</a></p>
1818
</blockquote>
1919
<h2 id="composite">Composite</h2>
20-
<h2 id="facade">Facade</h2>
21-
<h2 id="adapter">Adapter</h2>
22-
<h2 id="bridge">Bridge</h2>
23-
<h2 id="decorator">Decorator</h2>
24-
<h2 id="proxy">Proxy</h2>
25-
<h1 id="behavioral">Behavioral</h1>
26-
<blockquote>
27-
<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>
28-
<p><strong>Source:</strong> <a href="http://en.wikipedia.org/wiki/Behavioral_pattern">wikipedia.org</a></p>
29-
</blockquote>
30-
<h2 id="chain-of-responsibility">Chain Of Responsibility</h2>
31-
<h2 id="command">Command</h2>
32-
<h2 id="iterator">Iterator</h2>
33-
<h2 id="mediator">Mediator</h2>
34-
<h2 id="memento">Memento</h2>
35-
<h2 id="observer">Observer</h2>
36-
<h2 id="state">State</h2>
37-
<h2 id="strategy">Strategy</h2>
20+
<h2 id="fa-ade">Façade</h2>
3821

3922
</section>
4023
</div>

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,23 @@
1111
<body>
1212
<div class="content-wrapper">
1313
<section class="section">
14-
<h2 id="visitor">Visitor</h2>
14+
<h2 id="adapter">Adapter</h2>
15+
<h2 id="bridge">Bridge</h2>
16+
<h2 id="decorator">Decorator</h2>
17+
<h2 id="proxy">Proxy</h2>
18+
<h1 id="behavioral">Behavioral</h1>
19+
<blockquote>
20+
<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>
21+
<p><strong>Source:</strong> <a href="http://en.wikipedia.org/wiki/Behavioral_pattern">wikipedia.org</a></p>
22+
</blockquote>
23+
<h2 id="chain-of-responsibility">Chain Of Responsibility</h2>
24+
<h2 id="command">Command</h2>
25+
<h2 id="iterator">Iterator</h2>
26+
<h2 id="mediator">Mediator</h2>
27+
<h2 id="memento">Memento</h2>
28+
<h2 id="observer">Observer</h2>
29+
<h2 id="state">State</h2>
30+
<h2 id="strategy">Strategy</h2>
1531

1632
</section>
1733
</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 26</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>
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 28</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>

Design-Patterns.playground/contents.xcplayground

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,13 @@
4949
</code>
5050
<documentation relative-path="section-23.html">
5151
</documentation>
52+
<code source-file-name="section-24.swift">
53+
</code>
54+
<documentation relative-path="section-25.html">
55+
</documentation>
56+
<code source-file-name="section-26.swift">
57+
</code>
58+
<documentation relative-path="section-27.html">
59+
</documentation>
5260
</sections>
5361
</playground>
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
protocol PrintStrategy {
2-
func printString(string: String) -> String
3-
}
4-
5-
class Printer {
1+
let DEFAULT_POINT_BASE = 2.0
2+
let DEFAULT_POINT_POLARIZATION = false
63

7-
let strategy: PrintStrategy
8-
9-
func printString(string:String)->String
4+
class NotSoSimplePointConverter
5+
{
6+
func pointFrom(#x:Double,y:Double,z:Double,base:Double,negative:Bool) -> Point
107
{
11-
return self.strategy.printString(string);
12-
}
13-
14-
init(strategy: PrintStrategy){
15-
self.strategy = strategy
8+
var point = Point{
9+
$0.x = (x*base) * (negative ? -1.0 : 1.0)
10+
$0.y = (y*base) * (negative ? -1.0 : 1.0)
11+
$0.z = (z*base) * (negative ? -1.0 : 1.0)
12+
}
13+
14+
return point
1615
}
1716
}
1817

19-
class UpperCaseStrategy: PrintStrategy{
20-
func printString(string:String)->String{
21-
return string.uppercaseString;
22-
}
23-
}
18+
class OhSoSimplePointConverter{
19+
20+
func standarizedXYZFrom(#x:Double,y:Double,z:Double) -> (x:Double!,y:Double!,z:Double!){
21+
22+
let notSimple = NotSoSimplePointConverter()
23+
24+
var pointCalculated = notSimple.pointFrom(x:x,y:y,z:z,base:DEFAULT_POINT_BASE,negative:!DEFAULT_POINT_POLARIZATION)
2425

25-
class LowerCaseStrategy: PrintStrategy{
26-
func printString(string:String)->String{
27-
return string.lowercaseString;
26+
return (pointCalculated.x,pointCalculated.y,pointCalculated.z)
2827
}
28+
2929
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
var lower = Printer(strategy: LowerCaseStrategy())
2-
lower.printString("O tempora, o mores!")
1+
let simple = OhSoSimplePointConverter()
32

4-
var upper = Printer(strategy: UpperCaseStrategy())
5-
upper.printString("O tempora, o mores!")
3+
var tuple = simple.standarizedXYZFrom(x:1.1, y:2.2, z:3.3)
4+
5+
tuple.x
6+
tuple.y
7+
tuple.z
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
protocol PrintStrategy {
2+
func printString(string: String) -> String
3+
}
4+
5+
class Printer {
6+
7+
let strategy: PrintStrategy
8+
9+
func printString(string:String)->String
10+
{
11+
return self.strategy.printString(string);
12+
}
13+
14+
init(strategy: PrintStrategy){
15+
self.strategy = strategy
16+
}
17+
}
18+
19+
class UpperCaseStrategy: PrintStrategy{
20+
func printString(string:String)->String{
21+
return string.uppercaseString;
22+
}
23+
}
24+
25+
class LowerCaseStrategy: PrintStrategy{
26+
func printString(string:String)->String{
27+
return string.lowercaseString;
28+
}
29+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var lower = Printer(strategy: LowerCaseStrategy())
2+
lower.printString("O tempora, o mores!")
3+
4+
var upper = Printer(strategy: UpperCaseStrategy())
5+
upper.printString("O tempora, o mores!")

README.markdown

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,50 @@ Eduardo.name = "Eduardo"
156156
>**Source:** [wikipedia.org](http://en.wikipedia.org/wiki/Structural_pattern)
157157
158158
##Composite
159-
##Facade
159+
##Façade
160+
161+
```swift
162+
let DEFAULT_POINT_BASE = 2.0
163+
let DEFAULT_POINT_POLARIZATION = false
164+
165+
class NotSoSimplePointConverter
166+
{
167+
func pointFrom(#x:Double,y:Double,z:Double,base:Double,negative:Bool) -> Point
168+
{
169+
var point = Point{
170+
$0.x = (x*base) * (negative ? -1.0 : 1.0)
171+
$0.y = (y*base) * (negative ? -1.0 : 1.0)
172+
$0.z = (z*base) * (negative ? -1.0 : 1.0)
173+
}
174+
175+
return point
176+
}
177+
}
178+
179+
class OhSoSimplePointConverter{
180+
181+
func standarizedXYZFrom(#x:Double,y:Double,z:Double) -> (x:Double!,y:Double!,z:Double!){
182+
183+
let notSimple = NotSoSimplePointConverter()
184+
185+
var pointCalculated = notSimple.pointFrom(x:x,y:y,z:z,base:DEFAULT_POINT_BASE,negative:!DEFAULT_POINT_POLARIZATION)
186+
187+
return (pointCalculated.x,pointCalculated.y,pointCalculated.z)
188+
}
189+
190+
}
191+
```
192+
**Usage:**
193+
```swift
194+
let simple = OhSoSimplePointConverter()
195+
196+
var tuple = simple.standarizedXYZFrom(x:1.1, y:2.2, z:3.3)
197+
198+
tuple.x
199+
tuple.y
200+
tuple.z
201+
```
202+
160203
##Adapter
161204
##Bridge
162205
##Decorator

0 commit comments

Comments
 (0)