I have the following scenario. The client code only has access to FooHandler, not directly to Foo instances.
public delegate void FooLoaded(object sender, EventArgs e);
class Foo {
public event FooLoaded loaded;
/* ... some code ... */
public void Load() { load_asynchronously(); }
public void callMeWhenLoadingIsDone() { loaded(this,EventArgs.Empty); }
}
class FooHandler {
public event FooLoaded OneFooLoaded;
/* ... some code ... */
public void LoadAllFoos() {
foreach (Foo f in FooList) {
f.loaded += new FooLoaded(foo_loaded);
f.Load();
}
}
void foo_loaded(object sender, EventArgs e) {
OneFooLoaded(this, e);
}
}
Then the clients would use the OneFooLoaded event of the FooHandler class to get notifications of loading of foos. Is this 'event chaining' the right thing to do? Are there any alternatives? I don't like this (it feels wrong, I cannot precisely express why), but if I want the handler to be the point of access I don't seem to have many alternatives.