Skip to content

Instantly share code, notes, and snippets.

@sorin-ref
Last active December 5, 2018 18:48
Show Gist options
  • Save sorin-ref/afa90fb1303113f81f94ed2723bd01be to your computer and use it in GitHub Desktop.
Save sorin-ref/afa90fb1303113f81f94ed2723bd01be to your computer and use it in GitHub Desktop.
// 2. Service with default implementations that may be overriden at the client level through inheritance. Clients remain clean, and they can override only some of the open members, but they must have the service as their base class for this (and that's not always acceptable).
open class Service2 {
public init() { }
open func input() -> Bool {
return false
}
open func output(text: String) {
print(type(of: self), text)
}
public func doSomething() {
if input() {
output(text: "done")
}
}
}
class Client2: Service2 {
override func input() -> Bool { return true }
}
Client2().doSomething() // prints "Client2 done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment