Created
May 13, 2020 04:21
-
-
Save Happytreat/ccefe91facf1690f18a1a7e174212815 to your computer and use it in GitHub Desktop.
lost type relationship - without Self
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
/** | |
* Example from: Protocol-oriented Programming in Swift - WWDC 2015 | |
* https://developer.apple.com/videos/play/wwdc2015/408/ | |
*/ | |
class Ordered { | |
func precedes(other: Ordered) -> Bool { fatalError("implement me!") } | |
} | |
class Label : Ordered { var textL String = "" ... } | |
class Number: Ordered { | |
var value: Double = 0 | |
override func precedes(other: Ordered) -> Bool { | |
// forced down-cast here is generally a code smell | |
// even though we can make this an optional down-cast, it is still a sign that some type relationship is lost | |
return value < (other as! Number).value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment