I have a function with a lot of if
and else
and it looks very messy. I want to know if there is a better way to do this. This is a java function so feel free to suggest ways using try
and catch
, etc. My first two if
statements are checking if an object is null
or not. My third if
statement is checking if older time
is less than newer time
OR
one of the values is null
. If one of the values is null
, I want it to return true
. It is doing everything correctly right now but it is very messy as my code inside the third if
statement is messy as well. Is there a better way to do this? Any help will be appreciated.
My code: (I made the code more like web development for easier understanding)
if (customer != null)
{
if (customerDetails != null)
{
if ((olderTime == null || newerTime == null) || olderTime.before(newerTime))
{
// Some code here
}
else
{
console.log("Older Time must be before Newer Time");
}
}
else
{
console.log("Customer details doesn't exist");
}
}
else
{
console.log("Customer doesn't exist")
}
Aucun commentaire:
Enregistrer un commentaire