Can I avoid repeating myself in this situation (Java)
- by UltimateGuy
if (openFile == null) {
new AppFileDialog().chooseFile("Save", appFrame);
}
if (openFile == null) {
return;
}
Here I need to check to see if the user has already chosen a file. If not, they are given a prompt to. If the file is still null, the function returns without saving. The problem is the two identical if statements, can I avoid it? I take DRY very seriously, but at the same time KISS. Ideally the two go hand in hand, but in a situation like this, it seems they are mutually exclusive.