
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
356
|
Chapter 6: Iterators and Partial Types
See Also
See the “Iterators,” “yield,” “IEnumerator Interface,” and “IEnumerable Interface”
topics in the MSDN documentation.
6.10 Organizing Your Interface Implementations
Problem
You have a class that implements an interface with many methods. These methods
support only the interface functionality and don’t necessarily relate well to the other
code in your class. You would like to keep the interface implementation code sepa-
rate from the main class code.
Solution
Use partial classes to separate the interface implementation code into a separate file.
For example, you have a class called
TriValue that takes three decimal values and
performs some operations on them, like getting the average, the sum, and the prod-
uct. This code is currently in a file called TriValue.cs, which contains:
public partial class TriValue
{
decimal first;
decimal second;
decimal third;
public TriValue(decimal val1, decimal val2,decimal val3)
{
this.first = val1;
this.second = val2;
this.third = val3;
}
public TypeCode GetTypeCode( )
{
return TypeCode.Object;
}
public decimal GetAverage( )
{
return (GetSum( ) / 3);
}
public decimal GetSum( )
{
return first + second + third;
}
public decimal GetProduct( )
{