Timeline for Circumventing the Rules in Wizards and Warriors
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 23, 2017 at 13:39 | comment | added | Alex | Let us continue this discussion in chat. | |
Nov 23, 2017 at 13:39 | comment | added | CodingYoshi |
Yes it is broken. He also goes further to say that both a wizard and a warrior can use daggers. So now you need to add another method and when there is another weapon another method and so on. And even though a wizard cannot use a sword, you have setSword method defined in the Wizard .
|
|
Nov 23, 2017 at 13:36 | comment | added | Alex |
@CodingYoshi Now, that doesn't mean you can't write code that would require a runtime check e.g. if you try to add a Weapon to a Player . But there is no type system where you don't know the concrete types at compile time that can act on those concrete types at compile time. By definition. This scheme means that it is only that case that needs to be dealt with at runtime, As such is actually better than any of Eric's schemes.
|
|
Nov 23, 2017 at 13:32 | comment | added | Alex | @CodingYoshi The polymorphic requirement is that a Player has a Weapon. And in this scheme, the Player indeed has a Weapon. No inheritance is broken. This solution will only compile if you get the rules right. | |
Nov 23, 2017 at 13:03 | comment | added | CodingYoshi | Sorry couldn't change my comment once I realized you are not throwing excpetion. However, You broke the inheritance by doing that. See the issue the author was trying to solve is you cannot just add a method like you did because now the types cannot be treated polymorphically. | |
Nov 23, 2017 at 12:58 | comment | added | Alex | @CodingYoshi Why would this throw an exception? It's type safe i.e. checkable at compile time. | |
Nov 23, 2017 at 12:55 | comment | added | CodingYoshi | Eric Lippert did not want to throw exceptions. Did you read the series? The solution has to meet the requirements and this requirements are stated clearly in the series. | |
Nov 23, 2017 at 10:21 | history | answered | Alex | CC BY-SA 3.0 |