I have a requirement to implement following logic with multiple/nested if-else. Basically i have three tables and i need to insert record in one and delete from others based on different conditions (explained in code snippet below).
I have implemented it as below, just wondering is there a better/maintainable way to do it using OOPS and some design pattern in java
if (conditionA || conditionB || conditionC) {
deleteRecordFromTableA();
if (conditionB) {
insertRecordInTableB();
}
if (conditionC) {
insertRecordInTableB();
}
} else {
deleteRecordFromTableB();
deleteRecordFromTableC();
if (conditionD) {
validateRecordInUpdateMode();
updateRecordInTableA();
} else {
validateRecordInInsertMode();
insertRecordInTableA();
}
}