Skip to main content
Participant
Sep 18, 2008 4:58 PM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

2 replies

Participant
Sep 24, 2008 11:40 AM UTC
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.
Translate
Participating Frequently
Sep 24, 2008 11:19 AM UTC
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.
Translate