MVVM Fundación: ¿Por qué retorno ICommand cuando su define como RelayCommand
-
05-10-2019 - |
Pregunta
Estoy utilizando el proyecto de SampleModel MVVM Fundación .¿Por es ICommand
devuelve cuando se declara como _decrementCommand
RelayCommand
. Sé que hereda RelayCommand
ICommand
pero no voy a ser más claro es que acaba de regresar de una RelayCommand
?
public ICommand DecrementCommand {
get { return _decrementCommand ?? (_decrementCommand = new RelayCommand(() => --this.Value)); }
}
RelayCommand _decrementCommand;
Solución
This is the principle of using the least specific type you can get away with. Concrete or specific types are a liability because they are more likely to expose things that callers don't need to know about and they are more likely to need to be changed (making them an implementation detail).
In this case, if you always return ICommand, then you can change the underlying command type without breaking callers. You can also expect that the callers won't have to know more about what your function does than they actually should know, meaning that they will be less likely to break OO principles.