But in all seriousness real OO is directly against case statements like these.
It intends to group decisions about the kind of thing you have in a single place.
So an OO way of doing this would be to compute an Age class on a person and then have all Age rules apply to that age class.
So you could ask a person what age classification they have like Senior, Adult, Child, etc.. and all things related to being an Adult or Child would center there.
This is overkill of course, but that would be the OO spirit.
In Java this can be approximated with the very non-OO enum operator that can make these sorts of minimal type classes quite easy to build.
But the idea of removing if-elses is so that your program isn't riddled with the same if-else all over the place but maybe in only on place.
Of course often a simple if-else is just simpler then some complex idiom like subscribing age values to behavior via callbacks or listeners.
varlegalMessage=newImmutableRangeMap.<Integer,String>builder().put(null,"You're not a Person").put(lessThan(18),"Nope!!").put(closedOpen(18,21),"Not in the US!!").put(atLeast(21),"YES!!!").build();System.out.println(legalMessage.get(age));
In OO it's all about whether you're using the right objects or not. Many times people get sloppy. (This data structure comes from the Guava library)
Also overuse of if/else and case is not helped with FP popular error handling these days.
A nice thing about exceptions is that you can essentially ignore errors in most places rather than having and if/else everywhere or an error handler everywhere.
That style seems to be devolving into old styles where error handling is mixed in with the happy path making the code harder to read.
Classic OO (Smalltalk) and classic FP (if you consider Common Lisp FP) didn't even really have "if statements" or "case statements".
These were handled in the libraries.
I think modern OO languages biggest flaw is there over reliance on statements and keywords that make them much less extendable than Smalltalk or Lisp where you could literally change everything by extending the libraries.
Really no "modern" OO language really has that flexibility and clean design. Not Java, not C++, not C#, not Ruby, not Python, not JavaScript.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
But in all seriousness real OO is directly against case statements like these.
It intends to group decisions about the kind of thing you have in a single place.
So an OO way of doing this would be to compute an Age class on a person and then have all Age rules apply to that age class.
So you could ask a person what age classification they have like Senior, Adult, Child, etc.. and all things related to being an Adult or Child would center there.
This is overkill of course, but that would be the OO spirit.
In Java this can be approximated with the very non-OO enum operator that can make these sorts of minimal type classes quite easy to build.
But the idea of removing if-elses is so that your program isn't riddled with the same if-else all over the place but maybe in only on place.
Of course often a simple if-else is just simpler then some complex idiom like subscribing age values to behavior via callbacks or listeners.
But here's a modern Java example:
In OO it's all about whether you're using the right objects or not. Many times people get sloppy. (This data structure comes from the Guava library)
Nice one! Hard to believe that's Java. I agree, you can get sloppy with any language, even with Elixir, check this example:
Yeah that needs refactoring.
Also overuse of if/else and case is not helped with FP popular error handling these days.
A nice thing about exceptions is that you can essentially ignore errors in most places rather than having and if/else everywhere or an error handler everywhere.
That style seems to be devolving into old styles where error handling is mixed in with the happy path making the code harder to read.
Classic OO (Smalltalk) and classic FP (if you consider Common Lisp FP) didn't even really have "if statements" or "case statements".
These were handled in the libraries.
I think modern OO languages biggest flaw is there over reliance on statements and keywords that make them much less extendable than Smalltalk or Lisp where you could literally change everything by extending the libraries.
Really no "modern" OO language really has that flexibility and clean design. Not Java, not C++, not C#, not Ruby, not Python, not JavaScript.