Skip to content

Instantly share code, notes, and snippets.

@mayooresan
Created July 12, 2017 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayooresan/f6663cd4dc78e8a299d4278184eec06a to your computer and use it in GitHub Desktop.
Save mayooresan/f6663cd4dc78e8a299d4278184eec06a to your computer and use it in GitHub Desktop.
protocol Animal{
var isIdle : Bool? {get set}
func run()
func stop()
}
protocol Eye{
func closeEyesAndSleep()
func openEyesAndLookAround()
}
class Cat : Eye{
var isIdle: Bool? = true
func closeEyesAndSleep() {
if isIdle == true{
print("Cat is sleeping now")
}else{
print("Cat will NOT sleeping now")
}
}
func openEyesAndLookAround() {
print("Cat is looking around")
}
}
extension Cat : Animal{
func run() {
isIdle = true
print("Cat is running now")
}
func stop() {
isIdle = false
print("Cat has stopped now")
}
}
class Dog : Animal{
var isIdle: Bool? = true
func run() {
print("Dog is running now")
}
func stop() {
print("Dog has stopped now")
}
}
let whiteCat = Cat()
let blackCat = Cat()
let pinkCat = Cat()
let blackDog = Dog()
let yellowDog = Dog()
var animalsArray : [Animal] = [whiteCat, blackCat, pinkCat, blackCat, yellowDog]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment