This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol Service {} | |
| class RealService: Service {} | |
| class Client { | |
| let service: Service | |
| init() { | |
| service = RealService() | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func hangUpFirstCallOnAccountWithIdentifier(identifier: Int) { | |
| guard let account = accountRegistry.accountWithIdentifier(identifier) else { | |
| print("Could not find account") | |
| return | |
| } | |
| guard let call = account.firstCall else { | |
| print("Could not find first call for an account") | |
| return | |
| } | |
| call.hangUp() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol PhoneCall { | |
| var identifier: Int { get } | |
| var isNil: Bool { get } | |
| func hangUp() | |
| } | |
| class RealPhoneCall: PhoneCall { | |
| let identifier: Int | |
| let isNil = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PhoneCall { | |
| static let nullPhoneCall: PhoneCall = NullPhoneCall() | |
| let identifier: Int | |
| init(identifier: Int) { | |
| self.identifier = identifier | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func hangUpFirstCallOnAccountWithIdentifier(identifier: Int) { | |
| accountRegistry.accountWithIdentifier(identifier).firstCall.hangUp() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func hangUpFirstCallOnAccountWithIdentifier(identifier: Int) { | |
| if let account = accountRegistry.accountWithIdentifier(identifier) { | |
| if let call = account.firstCall { | |
| call.hangUp() | |
| } else { | |
| print("Could not find first call for an account") | |
| } | |
| } else { | |
| print("Could not find account") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol PhoneCallRegistry { | |
| func callWithIdentifier(identifier: Int) -> PhoneCall | |
| } | |
| func hangUpCallWithIdentifier(identifier: Int) { | |
| phoneCallRegistry.callWithIdentifier(identifier).hangUp() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol PhoneCallRegistry { | |
| func callWithIdentifier(identifier: Int) -> PhoneCall? | |
| } | |
| func hangUpCallWithIdentifier(identifier: Int) { | |
| if let call = phoneCallRegistry.callWithIdentifier(identifier) { | |
| call.hangUp() | |
| } else { | |
| print("Could not hang up call") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UserAgent { | |
| let observer: UserAgentObserver | |
| init(observer: UserAgentObserver) { | |
| self.observer = observer | |
| } | |
| func start() { | |
| observer.userAgentDidFinishStarting(self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UserAgent { | |
| let observer: UserAgentObserver | |
| init(observer: UserAgentObserver) { | |
| self.observer = observer | |
| } | |
| func start() { | |
| observer.userAgentDidFinishStarting(self) |