Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed dispatching to correct method and removed StackOverflowError #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kabutz
Copy link

@kabutz kabutz commented Mar 27, 2023

Mistake in article causes a StackOverflowError

@MBoegers
Copy link
Owner

Hi,
Thanks for submitting. I'm on vacation and try to answer until eastern.
Best Merlin

Comment on lines +21 to +23
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());
Copy link
Owner

@MBoegers MBoegers Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

@MBoegers
Copy link
Owner

And of course, this all happened because I omitted tests because "it just a demo".. I'll add some soon.

@kabutz
Copy link
Author

kabutz commented Mar 29, 2023

Of course, we all do that :-)

MBoegers added a commit that referenced this pull request Apr 2, 2023
@MBoegers
Copy link
Owner

MBoegers commented Apr 2, 2023

@kabutz I implemented tests and fixed the problem as suggested, see main. I'll close this PR okay?

@MBoegers MBoegers force-pushed the main branch 2 times, most recently from 8b440b7 to 713174e Compare July 23, 2023 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants