Fixed dispatching to correct method and removed StackOverflowError#1
Fixed dispatching to correct method and removed StackOverflowError#1kabutz wants to merge 1 commit intoMBoegers:mainfrom
Conversation
|
Hi, |
| if (kunde instanceof Privatkunde p) return calculateMwSt(p, wert); | ||
| else if (kunde instanceof Businesskunde b) return calculateMwSt(b, wert); | ||
| else throw new IllegalArgumentException("Unsupported type: " + kunde.getClass()); |
There was a problem hiding this comment.
The idea of MwStRechner.PlainOOP was to demonstrate a base implementation which is free of everything modern, like the Type Pattern.
To have a simple single step experience, I favor the pure instanceof Operator in this place. This way a Type Cast is required, but the demo of the Type Pattern may benefit also. The usage of the Type Pattern is demonstrated in the next step MwStRechner.InstanceOfPattern#calculateMwSt.
Suggestion for line 21-23:
if (kunde instanceof Privatkunde) return calculateMwSt((Privatkunde) p, wert);
else if (kunde instanceof Businesskunde) return calculateMwSt((Businesskunde)b, wert);
else throw new IllegalArgumentException("Unsupported type: " + kunde.getClass());|
And of course, this all happened because I omitted tests because "it just a demo".. I'll add some soon. |
|
Of course, we all do that :-) |
|
@kabutz I implemented tests and fixed the problem as suggested, see main. I'll close this PR okay? |
8b440b7 to
713174e
Compare
Mistake in article causes a StackOverflowError