otakusenpai
09/16/2018, 8:48 PMShawn
09/16/2018, 8:53 PMhow do I do it in Kotlinthe same way you’d do it in any language - group classes together based on the shape you expect them to have, i.e. the methods they expose
Shawn
09/16/2018, 8:54 PMWearable
sounds like a very base interface that doesn’t cover your armor use case if it doesn’t apply to all of your wearablesNikky
09/16/2018, 8:55 PMis
and when
when(wearable) {
is Stength -> { }
is Named -> { }
}
Nikky
09/16/2018, 8:55 PMShawn
09/16/2018, 8:56 PMgetTotalArmor()
methodNikky
09/16/2018, 8:56 PMif
Shawn
09/16/2018, 8:57 PMarmor
val and have items that don’t provide armor just return 0Nikky
09/16/2018, 8:57 PMShawn
09/16/2018, 8:57 PMotakusenpai
09/16/2018, 8:57 PMNikky
09/16/2018, 8:58 PMotakusenpai
09/16/2018, 8:59 PMNikky
09/16/2018, 8:59 PMif(wearable is Named)
interface Named {
var name: String
}
Nikky
09/16/2018, 9:00 PMotakusenpai
09/16/2018, 9:00 PMotakusenpai
09/16/2018, 9:01 PMNikky
09/16/2018, 9:01 PMwearabbles.filter { it is Named }
Nikky
09/16/2018, 9:01 PMotakusenpai
09/16/2018, 9:02 PMotakusenpai
09/16/2018, 9:02 PM