Last active
September 9, 2018 19:48
-
-
Save marcinjackowski/cc60216ef5c83f26aaa190b2bbcff946 to your computer and use it in GitHub Desktop.
[Final] #dependencyInversion
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
class FriendsService: FriendsWorker { | |
func fetch() -> [Friend] { | |
return [] | |
} | |
} | |
class FriendsDatabase: FriendsWorker { | |
func fetch() -> [Friend] { | |
return [] | |
} | |
} | |
class Profile { | |
private let worker: FriendsWorker | |
init(worker: FriendsWorker) { | |
self.worker = worker | |
fetch() | |
} | |
private func fetch() { | |
worker.fetch() | |
} | |
} | |
let friendsService = FriendsService() | |
let profileAPI = Profile(worker: friendsService) | |
let friendsDatabase = FriendsDatabase() | |
let profileDatabase = Profile(worker: friendsDatabase) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment