Skip to content

Commit 46519d0

Browse files
author
Sebastian Boldt
committed
Singleton and Prototype Pattern
1 parent 9c59524 commit 46519d0

File tree

7 files changed

+48
-20
lines changed

7 files changed

+48
-20
lines changed

β€ŽBehavioral.playground/Pages/Intro.xcplaygroundpage/Contents.swift

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//: [Previous](@previous)
2+
3+
import Foundation
4+
5+
struct ComplexToConstruct {
6+
public var complexToCompute : Int = {
7+
print("Constructed just once")
8+
var sum = 0
9+
for i in 0...100 {
10+
sum = sum + i
11+
}
12+
13+
return sum
14+
}()
15+
16+
17+
public func clone() -> ComplexToConstruct {
18+
return ComplexToConstruct(complexToCompute: self.complexToCompute)
19+
}
20+
}
21+
22+
let complex = ComplexToConstruct()
23+
complex.complexToCompute
24+
complex.clone().complexToCompute
25+
//: [Next](@next)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//: [Previous](@previous)
2+
3+
import Foundation
4+
5+
struct JustOnce {
6+
public static let internalInstance : JustOnce = JustOnce()
7+
private init() {}
8+
}
9+
10+
//: [Next](@next)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<playground version='6.0' target-platform='ios'>
3+
<pages>
4+
<page name='Singleton'/>
5+
<page name='Prototype'/>
6+
</pages>
7+
</playground>

β€ŽGOFSwift.xcworkspace/contents.xcworkspacedata

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€ŽREADME.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ Inspired by: https://github.com/ochococo/Design-Patterns-In-Swift
1818

1919
##Creational
2020

21+
* βœ… Singleton
22+
* βœ… Prototype
2123
* Abstract Factory
2224
* Builder
2325
* Factory Method
24-
* Prototype
25-
* Singleton
2626

2727
##Structural
2828

29-
* Adapter
3029
* βœ… Bridge
30+
* Adapter
3131
* Composite
3232
* Decorator
3333
* Facade

0 commit comments

Comments
Β (0)