P
puzzlecracker
Hello,
In general, it's a bad practice to call members in a derived class,
if the class hasn't been initialized. As a catchphrase goes, bad
things may happen. However, I think, my situation warrants to break
this rule, as I don't see anything going wrong. Plus, it really
alleviates my design constrains. Let me know what you think about
it.
Here is the example:
public interface IDisplay
{
public void Display();
}
public class XDisplay: IDisplay
{
public void Display() { /* display X widget */}
}
public class YDisplay: IDisplay
{
public void Display() { /* display Y widget */}
}
public abstract class ADisplayerPool
{
private IDisplay m_display=null;
protected abstract IDisplay CreateDisplay();
public AClass()
{
m_display =CreateDisplay();
}
}
public class DisplayPoolX : ADisplayerPool
{
protected IDisplay CreateDisplay() {return new XDisplay()}
}
public class DisplayPoolY : ADisplayerPool
{
protected IDisplay CreateDisplay() {return new YDisplay()}
}
Let me know if it's sound design or/and how you would restructure
it.
In general, it's a bad practice to call members in a derived class,
if the class hasn't been initialized. As a catchphrase goes, bad
things may happen. However, I think, my situation warrants to break
this rule, as I don't see anything going wrong. Plus, it really
alleviates my design constrains. Let me know what you think about
it.
Here is the example:
public interface IDisplay
{
public void Display();
}
public class XDisplay: IDisplay
{
public void Display() { /* display X widget */}
}
public class YDisplay: IDisplay
{
public void Display() { /* display Y widget */}
}
public abstract class ADisplayerPool
{
private IDisplay m_display=null;
protected abstract IDisplay CreateDisplay();
public AClass()
{
m_display =CreateDisplay();
}
}
public class DisplayPoolX : ADisplayerPool
{
protected IDisplay CreateDisplay() {return new XDisplay()}
}
public class DisplayPoolY : ADisplayerPool
{
protected IDisplay CreateDisplay() {return new YDisplay()}
}
Let me know if it's sound design or/and how you would restructure
it.