Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- }
- }
Add Comment
Please, Sign In to add comment