Last active
March 8, 2018 19:10
-
-
Save joanmolinas/4b7791b0c739f335ba6fccba341c7377 to your computer and use it in GitHub Desktop.
Blog.firstSolidPrinciples
This file contains hidden or 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 UserInformationHandler { | |
// MARK: - Properties | |
let requester: UserInformationRequesteable | |
let parser: UserInformationParseable | |
let storer: UserInformationStoreable | |
// MARK - Life cycle | |
init(requester: UserInformationRequesteable, | |
parser: UserInformationParseable, | |
storer: UserInformationStoreable) { | |
self.requester = requester | |
self.parser = parser | |
self.storer = storer | |
} | |
func handle() { | |
let data = requester.request() | |
let user = parser.parse(data: data) | |
storer.store(user: user) | |
} | |
} | |
protocol UserInformationRequesteable { | |
func request() -> Data | |
} | |
class UserInformationRequester: UserInformationRequesteable { | |
func request() -> Data { | |
// Interaction with the api | |
// Synchronous call for simplicity | |
} | |
} | |
protocol UserInformationParseable { | |
func parse(data: Data) | |
} | |
class UserInformationParser: UserInformationParseable { | |
func parse(data: Data) { | |
// parse data an create a dictionary | |
} | |
} | |
protocol UserInformationStoreable { | |
func store(user: [String: Any]) | |
} | |
class UserInformationStorer: UserInformationStoreable { | |
func store(user: [String: Any]) { | |
// store on your local database, the information of the user | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment