Delving Deeper into Interface-Based Programming - Interfaces and Partial Types
(Page 2 of 4 )
Partial types allow the component architect to define interface derivation for a class but have another developer implement it (similar to the old C++ distinction between header files and CPP files):
//In App.cs
public interface IMyInterface
{
void Method1();
void Method2();
}
public partial class MyClass : IMyInterface
{}
//In MyClass.cs
public partial class MyClass
{
public void Method1()
{...}
public void Method2()
{...}
}
With a partial class, each part of the class can choose to add interface derivation, or interface derivation and implementation:
public partial class MyClass
{}
public partial class MyClass : IMyInterface
{
public void Method1()
{...}
public void Method2()
{...}
}
However, only a single part can implement an interface member.
Next: Implementing Multiple Interfaces >>
More .NET Articles
More By O'Reilly Media
|
This article is excerpted from chapter three of Programming .NET Components, Second Edition, written by Juval Lowy (O'Reilly, 2006; ISBN: 0596007620). Check it out today at your favorite bookstore. Buy this book now.
|
|