I have too similar methods in two classes:
-----------------------DistributionFoo---------------------
class DistributionFoo : FooBase
{
private SortableBinding List<Distributi onRowStatusmSel ected;
private void DoSomething()
{
for (int i = 0; i < mSelected.Count ; i++)
{
DistributionRow Status lInstance = mSelected[i];
lInstance.Execu te();
ReportProgress( i / mSelected.Count , i);
if (mSelected.Coun t 1)
{
UpdateControls( );
}
}
}
}
-----------------------ReportFoo---------------------
class ReportFoo : FooBase
{
private SortableBinding List<ReportRowS tatusmSelected;
private void DoSomething()
{
for (int i = 0; i < mSelected.Count ; i++)
{
ReportRowStatus lInstance = mSelected[i];
lInstance.Execu te();
ReportProgress( i / mSelected.Count , i);
if (mSelected.Coun t 1)
{
UpdateControls( );
}
}
}
}
Since the methods, "DoSomethin g", in both classes, are identical
except for the lists that they operate on. mSelected in
"DistributionFo o" is a collection of "DistributionRo wStatus" type of
objects, while it is a collection of "ReportRowStatu s" type of ojects
in "ReportFoo" .
I want to move "DoSomethin g" method to the base class from child
classes so that both "DistributionFo o" and "ReportFoo" can share it.
However, I don't know how to handle "mSelected" .
I have code like below. I'm sure this doesn't work. Would welcome any
advice on how to make it work!
-----------------------FooBase---------------------
class FooBase
{
protected SortableBinding List<objectmSel ected;
protected void DoSomething()
{
for (int i = 0; i < mSelected.Count ; i++)
{
object lInstance = mSelected[i];
lInstance.Execu te();
ReportProgress( i / mSelected.Count , i);
if (mSelected.Coun t 1)
{
UpdateControls( );
}
}
}
}
-----------------------DistributionFoo---------------------
class DistributionFoo : FooBase
{
private SortableBinding List<Distributi onRowStatusmSel ected;
}
-----------------------ReportFoo---------------------
class ReportFoo : FooBase
{
private SortableBinding List<ReportRowS tatusmSelected;
}