I need to create and display several multiple choices dialogs. Those are dialogs with 3 or more buttons, like for instance “copy/move/link”, or “replace/overwrite/ignore”, that sort of thing.
I’m stuck with three competing implementation ideas, and none of them seems good enough:
- Creating dialogs for each problem, and returning the result as an enum,
- Creating a dynamic dialog that takes a vararg of String, turn them into buttons using the String as labels, and return the selected String as a result.
- Creating a dialog that take a vararg of DialogChoice, an interface I would create with a getText() method for the label and an act() method that is called when the DialogChoice is selected.
The first one will obviously produce redundant code, but the return type of the second one is quite dirty. The third seems the best so far, but it looks like some kind of disguised functional code and I’m not sure if that’s the healthy OO way of doing things.
So, is there another solution that I omitted, am I completely reinventing the wheel, or is one of these three ideas the best one?
Edit : I’m using JavaFx so there’s no built-in mechanisms that I could reuse, but it’s more of a general question that can be adapted to multiple frameworks, or even multiple languages. I only included the Java tag so as not to confuse people with the “enum” and “interface” keywords.
What makes you say that? It sounds oop to me.
A DialogChoice corresponds to an action and has a description. You encapsulate that in an object that lives on its own and is reusable.
The only “problem” is that it might increase verbosity, using anonymous classes and/or Runnables…