-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Dependency Inversion playground and updated README.md
- Loading branch information
Sebastian Boldt
committed
Mar 19, 2018
1 parent
7682b0f
commit 91ece77
Showing
12 changed files
with
125 additions
and
38 deletions.
There are no files selected for viewing
Binary file added
BIN
+6.36 KB
...round/playground.xcworkspace/xcuserdata/sboldt.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
Creational.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+6.08 KB
...round/playground.xcworkspace/xcuserdata/sboldt.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
Binary file modified
BIN
+2.85 KB
(110%)
GOFSwift.xcworkspace/xcuserdata/sboldt.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
SOLID.playground/Pages/Dependecny Inversion.xcplaygroundpage/Contents.swift
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
SOLID.playground/Pages/Dependency Inversion.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//: [Previous](@previous) | ||
|
||
import Foundation | ||
|
||
// The Problem - Tightly coupled classes | ||
|
||
struct Wrong { | ||
struct Datastore { | ||
// The Datastore should not know something about the Filehandler, it should use an abstraction instead | ||
let fileHandler: FileHandler = FileHandler() | ||
} | ||
|
||
struct FileHandler { | ||
func getFile(name: String) -> Data { | ||
return Data() | ||
} | ||
|
||
func storeFile(name: String, data: Data) { | ||
// Stores the File | ||
} | ||
} | ||
} | ||
|
||
|
||
// The Solution - Protocols and DI through the initalizer | ||
|
||
protocol FileHandlerProtocol { | ||
func getFile(name: String) -> Data | ||
func storeFile(name: String, data: Data) | ||
} | ||
|
||
struct Right { | ||
struct Datastore { | ||
let fileHandler: FileHandlerProtocol | ||
|
||
init(fileHandler: FileHandlerProtocol) { | ||
self.fileHandler = fileHandler | ||
} | ||
} | ||
|
||
struct FileHandler: FileHandlerProtocol { | ||
func getFile(name: String) -> Data { | ||
return Data() | ||
} | ||
func storeFile(name: String, data: Data) { | ||
// Store the File | ||
} | ||
} | ||
} | ||
|
||
|
||
//: [Next](@next) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='ios'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> | ||
<playground version='6.0' target-platform='ios'/> |
7 changes: 7 additions & 0 deletions
7
SOLID.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+6.07 KB
...round/playground.xcworkspace/xcuserdata/sboldt.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
Structural.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+6.08 KB
...round/playground.xcworkspace/xcuserdata/sboldt.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.