rinat_yakhin

social

May 29th, 2018
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. //: A UIKit based Playground for presenting user interface
  2.  
  3. import UIKit
  4.  
  5. class ContextClass {
  6.  
  7. enum Social {
  8. case vk
  9. case fb
  10. }
  11.  
  12. func getStrategy(type: Social) -> SocialNetworkStrategy {
  13. switch type {
  14. case .vk:
  15. return VKStrategy()
  16. case .fb:
  17. return FBStrategy()
  18. }
  19. }
  20. }
  21.  
  22. protocol SocialNetworkStrategy: class {
  23. func login()
  24. func logout()
  25. func sharePost()
  26. }
  27.  
  28. class VKStrategy: SocialNetworkStrategy {
  29. func login() {
  30. //do something
  31. print("vklogin")
  32. }
  33.  
  34. func logout() {
  35. //do something
  36. }
  37.  
  38. func sharePost() {
  39. //do something
  40. }
  41.  
  42.  
  43. }
  44.  
  45. class FBStrategy: SocialNetworkStrategy {
  46. func login() {
  47. //do something
  48. print("fblogin")
  49. }
  50.  
  51. func logout() {
  52. //do something
  53. }
  54.  
  55. func sharePost() {
  56. //do something
  57. }
  58. }
  59.  
  60. class GoogleStrategy: SocialNetworkStrategy {
  61. func login() {
  62. //do something
  63. }
  64.  
  65. func logout() {
  66. //do something
  67. }
  68.  
  69. func sharePost() {
  70. //do something
  71. }
  72.  
  73. }
  74.  
  75. // client
  76. let context = ContextClass()
  77. let social = context.getStrategy(type: .vk)
  78. social.login()
Add Comment
Please, Sign In to add comment