File tree 5 files changed +70
-3
lines changed
GOFSwift.xcworkspace/xcuserdata/sboldt.xcuserdatad
Protection Proxy.xcplaygroundpage
Virtual Proxy.xcplaygroundpage
5 files changed +70
-3
lines changed Original file line number Diff line number Diff line change 13
13
* ✅ Strategy
14
14
* ✅ Mediator
15
15
* ✅ Visitor
16
- * ❌ Interpreter
17
16
* ❌ Memento
17
+ * ❌ Interpreter
18
18
* ❌ Observer
19
19
* ❌ State
20
20
35
35
* ✅ Adapter
36
36
* ✅ Flyweight
37
37
* ✅ Facade
38
- * ❌ Protection Proxy
39
- * ❌ Virtual Proxy
38
+ * ✅ Protection Proxy
39
+ * ✅ Virtual Proxy
Original file line number Diff line number Diff line change
1
+ //: [Previous](@previous)
2
+
3
+ import Foundation
4
+
5
+ enum AuthError : Error {
6
+ case unauthorized
7
+ }
8
+
9
+ class PasswordStore {
10
+ func showSecretInformation( ) -> String {
11
+ return " SecretPassword "
12
+ }
13
+ }
14
+
15
+ class PasswordTresor {
16
+ var resourceToProtect : PasswordStore ?
17
+ func authenticate( password: String ) -> Bool {
18
+ guard password == " password " else {
19
+ return false
20
+ }
21
+ resourceToProtect = PasswordStore ( )
22
+ return true
23
+ }
24
+
25
+ func showSecretInformation( ) throws -> String {
26
+ guard let resourceToProtect = resourceToProtect else {
27
+ throw AuthError . unauthorized
28
+ }
29
+ return resourceToProtect. showSecretInformation ( )
30
+ }
31
+ }
32
+
33
+ //Usage
34
+
35
+ let tresor = PasswordTresor ( )
36
+ tresor. authenticate ( password: " password " )
37
+ try tresor. showSecretInformation ( )
38
+
39
+ //: [Next](@next)
Original file line number Diff line number Diff line change
1
+ //: [Previous](@previous)
2
+
3
+ import Foundation
4
+
5
+ protocol Server {
6
+ func compute( ) -> String
7
+ }
8
+
9
+ struct ExpensiveServer : Server {
10
+ func compute( ) -> String {
11
+ return " Computation completed "
12
+ }
13
+ }
14
+
15
+ class ExpensiveServerInterface : Server {
16
+ lazy private var expensiveServer = ExpensiveServer ( )
17
+
18
+ func compute( ) -> String {
19
+ return expensiveServer. compute ( )
20
+ }
21
+ }
22
+
23
+ let serverInterface = ExpensiveServerInterface ( )
24
+ serverInterface. compute ( )
25
+
26
+ //: [Next](@next)
Original file line number Diff line number Diff line change 7
7
<page name =' Adapter' />
8
8
<page name =' Flyweight' />
9
9
<page name =' Facade' />
10
+ <page name =' Protection Proxy' />
11
+ <page name =' Virtual Proxy' />
10
12
</pages >
11
13
</playground >
You can’t perform that action at this time.
0 commit comments