Зачем в этом примере наследование? - C#
Формулировка задачи:
Для того что бы лучше разбираться в программировании изучаю исходный код других программ.
Встретил такой код:
Не могу понять, зачем здесь нужен виртуальный класс и наследование?
/// <summary>
/// The base implementation of a command.
/// </summary>
public abstract class CommandBase
: ICommand
{
public event EventHandler CanExecuteChanged
{
add { System.Windows.Input.CommandManager.RequerySuggested += value; }
remove { System.Windows.Input.CommandManager.RequerySuggested -= value; }
}
public void OnCanExecuteChanged()
{
System.Windows.Input.CommandManager.InvalidateRequerySuggested();
}
public virtual bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
if (!CanExecute(parameter)) {
return;
}
OnExecute(parameter);
}
protected abstract void OnExecute(object parameter);
} /// <summary>
/// The command that relays its functionality by invoking delegates.
/// </summary>
public class RelayCommand
: CommandBase
{
private Action<object> execute;
private Func<object, bool> canExecute;
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
if (execute == null) {
throw new ArgumentNullException("execute");
}
if (canExecute == null) {
canExecute = (o) => true;
}
this.execute = execute;
this.canExecute = canExecute;
}
public override bool CanExecute(object parameter)
{
return canExecute(parameter);
}
protected override void OnExecute(object parameter)
{
execute(parameter);
}
}Решение задачи: «Зачем в этом примере наследование?»
textual
Листинг программы
public class RelayAsyncCommand: CommandBase
{
.......
}