Hi All...
i have a situation where i have 3 different Types (classes)
comming into a controling Class to Run Different Jobs
in my main loop i want to use 1 Field to hold a instance of the Class
currently Running example below
public class controler(
{
// how to use the below process for all 3 different Type?
// this is ccalled each time a run is started in
//different threads from the service
//i want to use one field to hold the current Process
//instead of using 3 Fields and if block
private Process
public controler(int iToRun)
{
if (iToRun==1)
{
Process = new Object1() ;
}
else if (iToRun==2)
{
Process = new Object2();
}
else
{
Process = new Object3();
}
}
public int Runjob()
{
int iRet=0;
if ( (iRet=Process.Execute())<=0)
{
//error occurred
}
else
{
//success
}
}
}
Tia
Analizer1
Jon Skeet [C# MVP] - 30 Oct 2007 18:41 GMT
> i have a situation where i have 3 different Types (classes)
> comming into a controling Class to Run Different Jobs
> in my main loop i want to use 1 Field to hold a instance of the Class
> currently Running example below
Create an interface (e.g. IExecutable) with all the methods that the
different types have in common (e.g. Execute()) and make all of the
types implement that interface.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nicholas Paldino [.NET/C# MVP] - 30 Oct 2007 18:42 GMT
Analizer1,
You should have all three objects implement a shared interface, and then
cast the objects to an instance of that interface. Then, you can call the
methods on the interface.
You could do this with reflection, but that's just messy.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Hi All...
> i have a situation where i have 3 different Types (classes)
[quoted text clipped - 41 lines]
> Tia
> Analizer1
Analizer1 - 30 Oct 2007 19:28 GMT
InterFace Worked Great....
Thanks alot
> Hi All...
> i have a situation where i have 3 different Types (classes)
[quoted text clipped - 41 lines]
> Tia
> Analizer1
sloan - 31 Oct 2007 20:37 GMT
Do a search on the "Command Design Pattern" as well, to learn some
caveats............
> Hi All...
> i have a situation where i have 3 different Types (classes)
[quoted text clipped - 41 lines]
> Tia
> Analizer1