Pergunta

I have a method that tries to get a ICommand instance and otherwise returns an ICommand with an Action that does nothing

private ICommand GetCommandFor(object o)
{
    if(CommandExistsFor(o))
    {
        return _commands[o];
    }
    return new Command(() => { });
}

Completely disregarding the fact that we have different levels of abstraction within that method and we are creating the Command ad-hoc (while this is functionally equivalent this isn't the real code anyway), I'd like to know how to name the command I'm returning if there is no command for o, either for documentation purposes (we are obliged to create XML docs for each method, also private ones) or if I extracted the line that creates the command.

Conceptually I'd call the command I am returning in the case that there is no valid command for o a null object, but it is not really a null object - at least not explicitly. I have thought about empty command or invariant command but I don't think that they transport the concept of what I am doing well enough. Or should I even create a NullCommand for that sole purpose, to make my intention even clearer?

Foi útil?

Solução

I would argue that the fact that the action does nothing is an implementation detail and so is not relevant to any comment or extracted method name. The key thing is that it is the default command supplied when there is no match.

Therefore the obvious term to use is DefaultCommand.

Licenciado em: CC-BY-SA com atribuição
scroll top