I'm pretty new to programming, but I've been trying to make sure I learn good design practices. My question is related to how to handle this sort of if-statement situation, as it seems to violate Don't Repeat Yourself.
I have a class with a constructor that includes a method to connect to a database. The method will write to a string if there was an error in the connection code block. I then have a process method that analyzes metadata of the database, and will also write errors if any are found. I don't want the metadata analysis to run if there was already an error in the connection method, but is this the best way to do this?:
public bool Process()
{
if (ErrorLog == null)
{
//Metadata analysis code that may write errors
if (ErrorLog == null)
return true;
else
PublishErrorLog();
return false;
}
else
PublishErrorLog();
return false;
}
Aucun commentaire:
Enregistrer un commentaire