Created
October 20, 2017 10:35
-
-
Save OdNairy/25052e0a3629be9563ce352aa570d5d2 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env swift | |
import Foundation | |
protocol TestProtocol { | |
func foo(_ param: Int) | |
} | |
extension TestProtocol { | |
func foo() { | |
print("Default implementation") | |
foo(0) | |
} | |
} | |
class API: TestProtocol { | |
private var _implementation: TestProtocol = MyApiUnderlineImplementation() | |
func foo(_ param: Int) { | |
_implementation.foo() | |
} | |
} | |
class MyApiUnderlineImplementation: TestProtocol { | |
func foo(_ param: Int) { | |
foo() | |
} | |
func foo() { | |
print("MyApiUnderlineImplementation") | |
} | |
} | |
let api = API() | |
api.foo() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment