G
Guest
Hello,
I am new to object oriented programming and .net. I have a question
concerning using singletons.
Lets say I have the following:
public class Engine
{
public static readonly Engine Instance = new Engine();//singleton
private Device device;
public Device Device
{
get{return device;}
}
//other stuff omitted
}
public class OtherClass
{
public void Method1()
{
Engine.Instance.Device.Method1
Engine.Instance.Device.Method2
Engine.Instance.Device.Method3
Engine.Instance.Device.Method4
}
}
Calling OtherClass.Method1 implemented this way, requires a device "get" 4
different times.
Would it be faster and/or better programming to create a local device
variable at the start of Method1 and set this equal Engine.Instance.Device?
public void Method1()
{
Device device = Engine.Instance.Device;
device.Method1
device.Method2
device.Method3
device.Method4
}
Any experienced advice would be greater appreciated.
Thanks,
Dan
I am new to object oriented programming and .net. I have a question
concerning using singletons.
Lets say I have the following:
public class Engine
{
public static readonly Engine Instance = new Engine();//singleton
private Device device;
public Device Device
{
get{return device;}
}
//other stuff omitted
}
public class OtherClass
{
public void Method1()
{
Engine.Instance.Device.Method1
Engine.Instance.Device.Method2
Engine.Instance.Device.Method3
Engine.Instance.Device.Method4
}
}
Calling OtherClass.Method1 implemented this way, requires a device "get" 4
different times.
Would it be faster and/or better programming to create a local device
variable at the start of Method1 and set this equal Engine.Instance.Device?
public void Method1()
{
Device device = Engine.Instance.Device;
device.Method1
device.Method2
device.Method3
device.Method4
}
Any experienced advice would be greater appreciated.
Thanks,
Dan