I have a class "Data" and a subclass "SubData". I want to access a method in SubData.
In order to do something like:
value = Data.SubData.getValue();
I need to make sure that Data!=null and also that SubData!=null.
I would usually do this:
if (Data!=null)
{
if (Data.SubData!=null)
{
value=Data.SubData.Value();
}
}
However when I want to print a message in case of Data or SubData being null, I need to put the message in two places:
if (Data!=null)
{
if (Data.SubData!=null)
{
value=Data.SubData.Value();
}
else
{
// MESSAGE
}
}
else
{
// MESSAGE
}
Is there a way of having //Message only in one place? Of course I could set a "showMessage flag" to true and then later have the message appear only in one place, but then I would still set the flag in two places.