views:

59

answers:

1

I am now trying to understand some code and I have found a pattern, which seem a bit strange to me. There is a user's control class with 'EditorOpen' event. At first, I thought this name is incorrect, because it does not end with '-ing' or '-ed', as MSDN suggests. However, later I have found out, that this event does not INFORM about something happening, but it is rather some kind of REQUEST to do the actual operation. This is the client code, which is expected to perform the "opening of the editor"!

I was a bit surprised to find out that this is actually some form of Template Method Design Pattern, in which there can be multiple actions connected with a single action placeholder.

I think it is quite interesting, but I am also afraid that using events in such cases may be highly misleading. Anyway, we are not talking about EVENTS here, but about REQUESTS. Hm... maybe it would be ok, if only the name of the event was 'EditorOpeningRequest' or 'EditorOpeningRequested'. What do you think? How would you comment this during a code review?

+1  A: 

Unless there is a very good reason for you to have multiple objects handling a request for opening an editor, I would suggest that should be a delegate instead of an event. This restricts you to having one handler of the request, which in this case seems more logical.

Further more I would change the name to OpenEditor as this is more descriptive as to what you're going to expect. If you do stick with the event model, then OpenEditorRequested may be a better name.

HTH.

Jonathan van de Veen