
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
156
|
Chapter 3: Classes and Structures
NotifyClient class. What if you add a second class, NotifyClientType2, which also
implements the
INotificationCallbacks interface? This new class is shown here:
public class NotifyClientType2 : INotificationCallbacks
{
public void FinishedProcessingSubGroup(int amount)
{
Console.WriteLine("[Type2] Finished processing " + amount + " items");
}
public void FinishedProcessingGroup( )
{
Console.WriteLine("[Type2] Processing complete");
}
}
The current code base cannot handle this new client notification type. To fix this
problem, you can replace all occurrences of the type
NotifyClient with the interface
type
INotificationCallbacks. This allows you to use any type of notification client
with your
Task and MultiTask objects. The modifications to these classes are high-
lighted in Example 3-14.
Example 3-14. Using multiple notification clients
public class Task
{
public Task(INotificationCallbacks notifyClient)
{
notificationObj = notifyClient;
}
INotificationCallbacks notificationObj = null;
public void AttachToCallback(INotificationCallbacks notifyClient)
{
notificationObj = notifyClient;
}
...
}
public class MultiTask
{
public MultiTask(INotificationCallbacks notifyClient)
{
notificationObjs.Add(notifyClient);
}
ArrayList notificationObjs = new ArrayList( ...