Skip to content

Instantly share code, notes, and snippets.

@robertmryan
Last active February 14, 2019 00:25
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 robertmryan/dde5d1b2addf210b87132c9b9534d54e to your computer and use it in GitHub Desktop.
Save robertmryan/dde5d1b2addf210b87132c9b9534d54e to your computer and use it in GitHub Desktop.
// if Knight is just initializing the properties of its super class, you can omit
// the init method entirely, and it will inherit it from its superclass
class Knight: Unit {
// override init(pHealthPoints: Int, pDamage: Int, pMovement: Int) {
// self.healthPoints = pHealthPoints
// self.damage = pDamage
// self.movement = pMovement
// }
}
// If, on the otherhand, `Knight` really need to have some of its own properties,
// as well, then set the subclasses' properties and then call `super.init`
class Knight: Unit {
let name: String
init(name: String, pHealthPoints: Int, pDamage: Int, pMovement: Int) {
self.name = name
super.init(pHealthPoints: pHealthPoints, pDamage: pDamage, pMovement: pMovement)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment