Last active
February 8, 2021 21:45
-
-
Save davidseek/4650d19184cb9b07f476425cbd9d27a2 to your computer and use it in GitHub Desktop.
human.swift
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 Human { | |
// The eat function returns an indicator, | |
// whether or not the food has been eaten. | |
// Our human has free choice. | |
func eat(_ food: Food) -> Bool { | |
// But they're a simple person, | |
// that eats everything that's edible. | |
return food.isEdible | |
} | |
} | |
// Now we want to define a sub-class of Human | |
// to give our objects a more detailed definition. | |
class Vegan: Human { | |
// We're overriding eat to change the output. | |
override func eat(_ food: Food) -> Bool { | |
// Our Vegan only eats edible food that's vegan. | |
return food.isEdible && food.isVegan | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment