D
Daniel Billingsley
Can someone please comment if there's something wrong from an OO point of
view with the model represented by the following code snippet. I hope it's
fairly obvious what the point is of the code I haven't explicitly included.
For purposes of this discussion let's say that classes derived from
SomeBaseClass my implement any combination of several interfaces.
Therefore, I'm not crazy about having a bunch of derived classes with all
possible combinations of them between SomeBaseClass and my final
instantiated class.
I suppose that SomeBaseClass shouldn't really have any idea what interfaces
a derived class might implement to be OO pure, but I also don't want to
repeat this code in all the derived classes. Maybe there is a better
solution??
=======================
class SomeBaseClass : SomeRootClass
{
protected void hookupChildListeners()
{
if (this is IManager)
{
((IManager)this).DirectReports.ListChanged += new
System.ComponentModel.ListChangedEventHander(childListChanged);
}
if (this is IBiologicalParent)
{
((IBiologicalParent)this).Children.ListChanged += new
System.ComponentModel.ListChangedEventHander(childListChanged);
}
if (this is IFosterParent)
{
((IFosterParent)this).Children.ListChanged += new
System.ComponentModel.ListChangedEventHander(childListChanged);
}
/// Etc. etc.
}
private void childListChanged(object sender,
System.ComponentModel.ListChangedEventArgs e)
{
onSomethingChanged(); // provides notification to interested
listeners that this object has changed.
}
}
-----------------------------
class SomeChildClass : SomeBaseClass, IBiologicalParent, IManager
{
private setup()
{
hookupChildListeners();
}
}
view with the model represented by the following code snippet. I hope it's
fairly obvious what the point is of the code I haven't explicitly included.
For purposes of this discussion let's say that classes derived from
SomeBaseClass my implement any combination of several interfaces.
Therefore, I'm not crazy about having a bunch of derived classes with all
possible combinations of them between SomeBaseClass and my final
instantiated class.
I suppose that SomeBaseClass shouldn't really have any idea what interfaces
a derived class might implement to be OO pure, but I also don't want to
repeat this code in all the derived classes. Maybe there is a better
solution??
=======================
class SomeBaseClass : SomeRootClass
{
protected void hookupChildListeners()
{
if (this is IManager)
{
((IManager)this).DirectReports.ListChanged += new
System.ComponentModel.ListChangedEventHander(childListChanged);
}
if (this is IBiologicalParent)
{
((IBiologicalParent)this).Children.ListChanged += new
System.ComponentModel.ListChangedEventHander(childListChanged);
}
if (this is IFosterParent)
{
((IFosterParent)this).Children.ListChanged += new
System.ComponentModel.ListChangedEventHander(childListChanged);
}
/// Etc. etc.
}
private void childListChanged(object sender,
System.ComponentModel.ListChangedEventArgs e)
{
onSomethingChanged(); // provides notification to interested
listeners that this object has changed.
}
}
-----------------------------
class SomeChildClass : SomeBaseClass, IBiologicalParent, IManager
{
private setup()
{
hookupChildListeners();
}
}