I'm just looking for some feedback. Alternatives would also be interesting!
I have a base class with a Size and Location. I also have a class that inherits from that base, but it doesn't care about the Size and Location being logged to Console. Of the two options below, which is more correct way to prevent the Console.WriteLine?
Size and Location var's must remain on the base class, and the Console.WriteLine must happen for all classes except SomeFoo if you choose to write a 3rd option=)
.NET 2.0
1:
public class FooBase
{
Size mySize = new Size();
Point myLocation = new Point();
protected virtual void CallMeSomeTimeAfterMyClassIsConstructed()
{
if (myLocation.IsEmpty && mySize.IsEmpty)
{
Console.WriteLine("Size and Location are empty.");
}
}
}
public class SomeFoo : FooBase
{
protected override void CallMeSomeTimeAfterMyClassIsConstructed()
{
}
}
2:
public class FooBase
{
protected bool hasSizeAndLocation = true;
Size mySize = new Size();
Point myLocation = new Point();
private void CallMeSomeTimeAfterMyClassIsConstructed()
{
if (hasSizeAndLocation && myLocation.IsEmpty && mySize.IsEmpty)
{
Console.WriteLine("Size and Location are empty.");
}
}
}
public class SomeFoo : FooBase
{
public SomeFoo()
{
this.hasSizeAndLocation = false;
}
}