473,795 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Issue with moving a common method to base class

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;

}
Dec 7 '07 #1
3 1420
I haven't tried this, but how about creating a common interface that each
type works against?

internal interface IBaseElement
{
void Execute();
}

internal abstract class baseclass<Twher e T : IBaseElement
{
protected List<TmSelected ;

protected baseclass()
{
mSelected = new List<T>();
}

protected abstract Type GetElementType( );
protected abstract void ReportProgress( decimal percentComplete , int
position);
protected abstract void UpdateControls( );
protected void DoSomething()
{

for (int i = 0; i < mSelected.Count ; i++)
{

IBaseElement tempElement = (IBaseElement)m Selected[i];

tempElement.Exe cute();

ReportProgress( i / mSelected.Count , i);

if (mSelected.Coun t 1)
{
UpdateControls( );
}
}
}
}

internal class DistributionRow Status : IBaseElement
{

#region IBaseElement Members

public void Execute()
{
//
}

#endregion
}

internal class ReportRowStatus : IBaseElement
{

#region IBaseElement Members

public void Execute()
{
//
}

#endregion
}

internal class Class1 : baseclass<Distr ibutionRowStatu s>
{
public Class1():base()
{
//
}

protected override Type GetElementType( )
{
return System.Type.Get Type("Distribut ionRowStatus");
}

protected override void ReportProgress( decimal percentComplete , int
position)
{
//Do custom work here
}

protected override void UpdateControls( )
{
//Do custom work here
}
}

internal class Class2 : baseclass<Repor tRowStatus>
{
public Class2(): base()
{
//
}

protected override Type GetElementType( )
{
return System.Type.Get Type("ReportRow Status");
}

protected override void ReportProgress( decimal percentComplete , int
position)
{
//Do custom work here
}

protected override void UpdateControls( )
{
//Do custom work here
}
}

"Curious" <fi********@yah oo.comwrote in message
news:2c******** *************** ***********@l16 g2000hsf.google groups.com...
>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;

}

Dec 7 '07 #2
Hi Amdrit,

Thanks for the advice! Are you suggesting using generics? I'll try it
out.
Dec 7 '07 #3
Hi Amdrit,

I don't know how your code works. Would you answer my questions below:

1) mSelected is passed to each child class. Is there a need to define
construction of baseclass in baseclass?

2) Since you've defined "GetElementType ", where do you use it in the
base class?

3) What are "class1" and "class2"? Are they redundent with
"DistributionRo wStatus" and "ReportRowStatu s"?

Thanks,
Dec 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6816
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what the issue is. Thanks Ravi
15
5964
by: Ladvánszky Károly | last post by:
Entering 3.4 in Python yields 3.3999999999999999. I know it is due to the fact that 3.4 can not be precisely expressed by the powers of 2. Can the float handling rules of the underlying layers be set from Python so that 3.4 yield 3.4? Thanks, Károly
3
4143
by: CaribSoft | last post by:
I want to create my own common dialog to use in an application . How do I show a custom dialog (form) in a class based on the common dialog class?
3
1418
by: jqpdev | last post by:
Hello all, I've been developing web apps using Borland's websnap technology which is built upon asp technology. I'm tranisitioning to ASP.NET VS.NET and need some techniques/best practices to assist in the transition. I've created my apps/sites using a chunking method based on a template. Chunks of HTML and JScript are stored together in separate files, and groups of pages share a common template file. Most of the pages have their...
5
3199
by: wrecker | last post by:
Hi all, I have a few common methods that I need to use at different points in my web application. I'm wondering where the best place would be to put these? I think that I have three options. 1. I can create a common module like common.vb in my project and put all the functions in there. 2. Create a utility class and create the common functions as shared
2
9379
by: Diogo Alves - Software Developer | last post by:
Greetings I would like to knowhow can I put a sliding panel... I've done this: if (panel1.Width < 300) { while (panel1.Width < 300) { panel1.Width = panel1.Width + 40;
5
1991
by: toton | last post by:
Hi, I want a few of my class to overload from a base class, where the base class contains common functionality. This is to avoid repetition of code, and may be reducing amount of code in binary, not to get polymorphic behavior. None of them has virtual methods, and are self contained (no destructor at all) thus do not have a chance to have memory error. Thus the derived classes has additional functionality, not additional data.
11
1817
by: =?Utf-8?B?R29rdWw=?= | last post by:
I am struck up with a problem and want anyone here to help me out. I am a beginner in .NET trying to learng DataBinding concepts. I have binded 4 text boxes with a dataset but when I say adapter.update it gives me 0 records updated! I am not getting any exceptions. Below is the complete code. Someone please help me out. using System; using System.Drawing; using System.Collections; using System.ComponentModel;
15
3538
by: Juha Nieminen | last post by:
I'm sure this is not a new idea, but I have never heard about it before. I'm wondering if this could work: Assume that you have a common base class and a bunch of classes derived from it, and you want to make a deque which can contain any objects of any of those types. Normally what you would have to do is to make a deque or vector of pointers of the base class type and then allocate each object dynamically with 'new' and store the...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.