File tree 4 files changed +48
-1
lines changed
Pages/State.xcplaygroundpage
GOFSwift.xcworkspace/xcuserdata/sboldt.xcuserdatad
Structural.playground/Pages/Flyweight.xcplaygroundpage
4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change
1
+ //: [Previous](@previous)
2
+
3
+ import Foundation
4
+
5
+ protocol State {
6
+ var isAuthorized : Bool { get }
7
+ }
8
+
9
+ final class UserContext {
10
+ private var userId : String
11
+ private var state : State = UnauthorizedState ( )
12
+
13
+ init ( userID: String ) {
14
+ self . userId = userId
15
+ }
16
+
17
+ var isAuthorized : Bool {
18
+ self . state. isAuthorized
19
+ }
20
+ public func changeToAuthorizedState( ) {
21
+ self . state = AuthorizedState ( )
22
+ }
23
+
24
+ public func changeToUnauthorizedState( ) {
25
+ self . state = UnauthorizedState ( )
26
+ }
27
+ }
28
+
29
+ struct AuthorizedState : State {
30
+ var isAuthorized : Bool {
31
+ return true
32
+ }
33
+ }
34
+
35
+ struct UnauthorizedState : State {
36
+ var isAuthorized : Bool {
37
+ return false
38
+ }
39
+ }
40
+
41
+ var context = UserContext ( userID: UUID ( ) . uuidString)
42
+ context. changeToAuthorizedState ( )
43
+ context. isAuthorized
44
+
45
+ //: [Next](@next)
Original file line number Diff line number Diff line change 6
6
<page name =' Iterator' />
7
7
<page name =' Strategy' />
8
8
<page name =' Mediator' />
9
- <page name =' Observer' />
10
9
<page name =' Visitor' />
11
10
<page name =' Memento' />
11
+ <page name =' Observer' />
12
+ <page name =' State' />
12
13
</pages >
13
14
</playground >
Original file line number Diff line number Diff line change 1
1
//: [Previous](@previous)
2
2
3
3
import Foundation
4
+ import CoreGraphics
4
5
5
6
protocol Soldier {
6
7
func render( from location: CGPoint , to newLocation: CGPoint )
You canβt perform that action at this time.
0 commit comments