Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. protocol ServiceAProtocol {
  2. func performTaskA()
  3. }
  4.  
  5. protocol ServiceBProtocol {
  6. func performTaskB()
  7. }
  8.  
  9. class ServiceA: ServiceAProtocol {
  10. func performTaskA() {
  11. print("performing task A ....")
  12. }
  13. }
  14.  
  15. class ServiceB: ServiceBProtocol {
  16. func performTaskB() {
  17. print("performing task B ....")
  18. }
  19. }
  20.  
  21. class Client {
  22. var serviceA: ServiceAProtocol?
  23. var serviceB: ServiceBProtocol?
  24. init() {}
  25. func performTasks() {
  26. // will optionally call services
  27. self.serviceA?.performTaskA()
  28. self.serviceB?.performTaskB()
  29. }
  30. }
  31.  
  32. // Injector code
  33. let client = Client()
  34. client.serviceA = ServiceA()
  35. client.serviceB = ServiceB()
  36. client.performTasks()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement