C
Curious
I have too similar methods in two classes:
-----------------------DistributionFoo---------------------
class DistributionFoo : FooBase
{
private SortableBindingList<DistributionRowStatus> mSelected;
private void DoSomething()
{
for (int i = 0; i < mSelected.Count; i++)
{
DistributionRowStatus lInstance = mSelected;
lInstance.Execute();
ReportProgress(i / mSelected.Count, i);
if (mSelected.Count > 1)
{
UpdateControls();
}
}
}
}
-----------------------ReportFoo---------------------
class ReportFoo : FooBase
{
private SortableBindingList<ReportRowStatus> mSelected;
private void DoSomething()
{
for (int i = 0; i < mSelected.Count; i++)
{
ReportRowStatus lInstance = mSelected;
lInstance.Execute();
ReportProgress(i / mSelected.Count, i);
if (mSelected.Count > 1)
{
UpdateControls();
}
}
}
}
Since the methods, "DoSomething", in both classes, are identical
except for the lists that they operate on. mSelected in
"DistributionFoo" is a collection of "DistributionRowStatus" type of
objects, while it is a collection of "ReportRowStatus" type of ojects
in "ReportFoo".
I want to move "DoSomething" method to the base class from child
classes so that both "DistributionFoo" 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 SortableBindingList<object> mSelected;
protected void DoSomething()
{
for (int i = 0; i < mSelected.Count; i++)
{
object lInstance = mSelected;
lInstance.Execute();
ReportProgress(i / mSelected.Count, i);
if (mSelected.Count > 1)
{
UpdateControls();
}
}
}
}
-----------------------DistributionFoo---------------------
class DistributionFoo : FooBase
{
private SortableBindingList<DistributionRowStatus> mSelected;
}
-----------------------ReportFoo---------------------
class ReportFoo : FooBase
{
private SortableBindingList<ReportRowStatus> mSelected;
}
-----------------------DistributionFoo---------------------
class DistributionFoo : FooBase
{
private SortableBindingList<DistributionRowStatus> mSelected;
private void DoSomething()
{
for (int i = 0; i < mSelected.Count; i++)
{
DistributionRowStatus lInstance = mSelected;
lInstance.Execute();
ReportProgress(i / mSelected.Count, i);
if (mSelected.Count > 1)
{
UpdateControls();
}
}
}
}
-----------------------ReportFoo---------------------
class ReportFoo : FooBase
{
private SortableBindingList<ReportRowStatus> mSelected;
private void DoSomething()
{
for (int i = 0; i < mSelected.Count; i++)
{
ReportRowStatus lInstance = mSelected;
lInstance.Execute();
ReportProgress(i / mSelected.Count, i);
if (mSelected.Count > 1)
{
UpdateControls();
}
}
}
}
Since the methods, "DoSomething", in both classes, are identical
except for the lists that they operate on. mSelected in
"DistributionFoo" is a collection of "DistributionRowStatus" type of
objects, while it is a collection of "ReportRowStatus" type of ojects
in "ReportFoo".
I want to move "DoSomething" method to the base class from child
classes so that both "DistributionFoo" 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 SortableBindingList<object> mSelected;
protected void DoSomething()
{
for (int i = 0; i < mSelected.Count; i++)
{
object lInstance = mSelected;
lInstance.Execute();
ReportProgress(i / mSelected.Count, i);
if (mSelected.Count > 1)
{
UpdateControls();
}
}
}
}
-----------------------DistributionFoo---------------------
class DistributionFoo : FooBase
{
private SortableBindingList<DistributionRowStatus> mSelected;
}
-----------------------ReportFoo---------------------
class ReportFoo : FooBase
{
private SortableBindingList<ReportRowStatus> mSelected;
}