Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protocol ServiceAProtocol {
- func performTaskA()
- }
- protocol ServiceBProtocol {
- func performTaskB()
- }
- class ServiceA: ServiceAProtocol {
- func performTaskA() {
- print("performing task A ....")
- }
- }
- class ServiceB: ServiceBProtocol {
- func performTaskB() {
- print("performing task B ....")
- }
- }
- class Client {
- var serviceA: ServiceAProtocol?
- var serviceB: ServiceBProtocol?
- init() {}
- func performTasks() {
- // will optionally call services
- self.serviceA?.performTaskA()
- self.serviceB?.performTaskB()
- }
- }
- // Injector code
- let client = Client()
- client.serviceA = ServiceA()
- client.serviceB = ServiceB()
- client.performTasks()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement