I have a code that I want to reorganize. I have many methods that take multiple arguments of the same type, for example:
public void foo(String name, String street, boolean b1, boolean b2) { ... }
etc. Since different objects can only be selected by name, I would like to wrap them in Object (Enums) so that I can use the language system for the language (Java in this case).
public class Name { private String value; public String getValue() { return value; }
Similarly, I can make the call code pass in Objects of a certain type. This would assure that this would not lead to an inadvertent confusion of the order of the method parameters, and therefore would not lead to unexpected runtime behavior :
foo(new Name("John"), new Street("Broadway"), new B1(true), new B2(false);
This makes refactoring safer , you can transfer an object through the system as long as you want, the data inside it, the string is always safe. Only when you need it will you get it by calling getValue ().
Now, for objects that wrap strings, it's pretty simple, since there are many state instances.
But what about boolean wrappers? It is either TRUE or FALSE. The implementation just looks, well, a little ridiculous:
public enum Quanto { YES() { protected boolean isQuanto() { return true; } }, NO() { protected boolean isQuanto() { return false; } }; protected abstract boolean isQuanto(); }
Even a stranger, I find what the call code looks like:
public void doStuff(Quanto quanto) { if(quanto.isQuanto()) {
Technically, it doesn't matter, but it's just not. Have you found the βbestβ ways to deal with this?
EDIT: What also does not satisfy me is the fact that in the above example there are more values ββthan YES and NO , say POSSIBLE ...?!
Thanks!