Created
August 31, 2018 08:45
-
-
Save kateinoigakukun/45e5fe1cbb6e1d0d4f093e45b97082f0 to your computer and use it in GitHub Desktop.
This file contains 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 Animal {} | |
extension Animal { | |
init(_animal: Self) { | |
self = _animal | |
} | |
} | |
class AnimalBase: Animal { | |
convenience init(with animal: AnimalBase) { | |
self.init(_animal: animal) | |
} | |
} | |
class Cat: AnimalBase { | |
let _name = "Tama" | |
var name: String { return _name } | |
func bark() { | |
print(name) | |
} | |
} | |
class Dog: AnimalBase {} | |
let animal = Cat(with: Dog()) | |
animal.bark() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment