Skip to main content
Participant
September 18, 2008
Question

Make ICommand a marker interface to avoid cast of event in command

  • September 18, 2008
  • 2 replies
  • 725 views
I'd like to remove the execute method from ICommand.

Pro: We can declare the execute method with the concrete event class. No need to upcast the CairngormEvent inside execute.

//currently
public void execute( event : CairngormEvent ) : void
{
var concreteEvent : ConcreteEvent = event as ConcreteEvent;
}

//with ICommand being a marker interface
public void execute( event : ConcreteEvent ) : void
{
//no need for a cast here
}

Contra: We loose the compile time check for the execute method being implemented.

Thoughts?
This topic has been closed for replies.

2 replies

Participant
September 24, 2008
Hi David

Inside the FrontController we can call the execute method dynamically, eg. something like command["execute"](event). So we don't really need to declare the method. Obviously we loose some type safety through this but we gain less clutter in the command.

Cheers
Ralf.
Participating Frequently
September 24, 2008
Hello Ralf

You're right about the fact that having to cast the event in your commands is pretty annoying. However, I think the ICommand interface has to declare the execute method since the FrontController has to call this method in response to the corresponding CairngormEvent.
So, IMHO, we should probably keep it this way.