-1

What's the diferente between this code?

interface ICommandHanddler<T> where T : ICommand
    {
        void Handle(T command);
    }

and this code:

interface ICommandHanddler<ICommand>
    {
        void Handle(ICommand command);
    }

For me it's have the same impact in my software, but i wanna know if that really dont impact anything or it's just a good practice

Italo José
  • 1,558
  • 1
  • 17
  • 50

1 Answers1

0

The former says: "Interface of type CLASS where CLASS is an extension of ICommand" The latter says: "Interface of type ICommand"

The former allows you to call your ICommandHanddler interface with multiple types of objects so long as they inherit ICommand, or are ICommand.

On the impact of your program: if you have multiple classes that extend from a common parent and override the same function, it's going to make your life a lot easier and more organized to do the former method. If you only have the ICommand class, then you're fine doing the latter. It's all dependent on how you plan on build and extending your classes.

Wrinn
  • 98
  • 1
  • 13