Help explaining come code (interfaces)
Hello,
I have some code that I have written from a tutorial. Even though I understand what the code is doing. I don't understand some of the coding itself.
Meaning this:
Code:
IDeviceEmulatorManager emulatorManager;
and this:
Code:
emulatorManager = new DeviceEmulatorManagerClass();
I can understand that is creating a object of the DeviceEmulatorManagerClass so you can you its methods and properties etc. But I am not sure of why you need the interface?
Many thanks for any advice,
Steve
The complete code is listed below.
Code:
IDeviceEmulatorManager emulatorManager;
private void Form1_Load(object sender, EventArgs e)
{
emulatorManager = new DeviceEmulatorManagerClass();
}
private void btnPopulate_Click(object sender, EventArgs e)
{
this.ListDEMAllMembers();
}
void ListDEMAllMembers()
{
string categoryName;
this.lstDisplay.Items.Clear();
emulatorManager.Reset();
while (true)
{
categoryName = emulatorManager.get_Name();
lstDisplay.Items.Add(categoryName);
emulatorManager.MoveNext();
}
}
Re: Help explaining come code (interfaces)
From this MSDN topic, which I found by searching for deviceemulatormanagerclass:
Quote:
To get started with the Device Emulator Manager API, you must first create an instance of the Device Emulator Manager. You do this by creating an instance of the DeviceEmulatorManagerClass class. This class encapsulates the COM component that represents the Device Emulator Manager. When working with the Device Emulator Manager, you can use the DeviceEmulatorManagerClass class directly or use the IDeviceEmulatorManager interface. Both the class and the interface provide all of the same methods. For consistency with the interface-based nature of COM, this paper uses the interface as shown in the following code sample.
Code:
IDeviceEmulatorManager _emulatorManager;
_emulatorManager = new DeviceEmulatorManagerClass();