Guest User

Untitled

a guest
Mar 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. class UserInformationHandler {
  2.  
  3. // MARK: - Properties
  4. let requester: UserInformationRequesteable
  5. let parser: UserInformationParseable
  6. let storer: UserInformationStoreable
  7.  
  8. // MARK - Life cycle
  9. init(requester: UserInformationRequesteable,
  10. parser: UserInformationParseable,
  11. storer: UserInformationStoreable) {
  12. self.requester = requester
  13. self.parser = parser
  14. self.storer = storer
  15. }
  16.  
  17. func handle() {
  18. let data = requester.request()
  19. let user = parser.parse(data: data)
  20. storer.store(user: user)
  21. }
  22. }
  23.  
  24. protocol UserInformationRequesteable {
  25. func request() -> Data
  26. }
  27.  
  28. class UserInformationRequester: UserInformationRequesteable {
  29. func request() -> Data {
  30. // Interaction with the api
  31. // Synchronous call for simplicity
  32. }
  33. }
  34.  
  35. protocol UserInformationParseable {
  36. func parse(data: Data)
  37. }
  38.  
  39. class UserInformationParser: UserInformationParseable {
  40. func parse(data: Data) {
  41. // parse data an create a dictionary
  42. }
  43. }
  44.  
  45. protocol UserInformationStoreable {
  46. func store(user: [String: Any])
  47. }
  48.  
  49. class UserInformationStorer: UserInformationStoreable {
  50. func store(user: [String: Any]) {
  51. // store on your local database, the information of the user
  52. }
  53. }
Add Comment
Please, Sign In to add comment