// All of these invocations call the
// same Draw() method!
Octagon oct = new Octagon();
oct.Draw();
IDrawToForm itfForm = (IDrawToForm)oct;
itfForm.Draw();
IDrawToPrinter itfPriner = (IDrawToPrinter)oct;
itfPriner.Draw();
IDrawToMemory itfMemory = (IDrawToMemory)oct;
itfMemory.Draw();
Console.ReadLine();
}
Clearly, the sort of code required to render the image to a window is quite different from the
code needed to render the image to a networked printer or a region of memory. When you imple-
ment a collection of interfaces that have identical members, you can resolve this sort of name clash
using
explicit interface implementation syntax. Consider the following update to the Octagon type:
class Octagon : IDrawToForm, IDrawToMemory, IDrawToPrinter
{
Do'stlaringiz bilan baham: |