I recently learned about Presenter First and read their bulletins and blogs, etc.
In most of the examples I found, events are not declared directly on the interface, but rather as a method for it. For example,
public interface IPuzzleView
{
void SubscribeMoveRequest(PointDelegate listener);
event PointDelegate MoveRequest;
}
I donβt understand why. It seemed to me that somewhere I saw a paper / article / blog explaining the reasons for this, but I can no longer find it. The text also contains fragments of unit testing code - I know this because I remember telling myself that one of the unit test was wrong.
UPDATE:
The following is an example of a comparison:
public class Collect
{
public static CollectAction<T> Argument<T>(int index,
CollectAction<T>.Collect collectDelegate)
{
CollectAction<T> collect = new CollectAction<T>(index, collectDelegate);
return collect;
}
}
public interface IApplicationView
{
event EventHandler Load;
void SubscribeLoad(Action action);
}
Mockery mockery = new Mockery();
IApplicationView view = mockery.NewMock<IApplicationView>();
IApplicationModel model = mockery.NewMock<IApplicationModel>();
Subscription Style:
Action savedAction = null;
Expect.Once.On(view).Method("SubscribeLoad").Will(
Collect.Argument<Action>(0,
delegate(Action action) { savedAction = action; }));
Expect.Once.On(model).Method("LoadModules");
new ApplicationPresenter(view, model);
savedAction();
mockery.VerifyAllExpectationsHaveBeenMet();
vs. Event:
Expect.Once.On(view).EventAdd("Load", Is.Anything);
Expect.Once.On(model).Method("LoadModules");
new ApplicationPresenter(view, model);
Fire.Event("Load").On(view);
mockery.VerifyAllExpectationsHaveBeenMet();
FYI, , ApplicationPresenter , .