1

I come from a C++ background.

If I'm not going to implement the method, what's the point of giving arbitrary identifiers to the parameters? Aren't the identifiers supposed to be tied to the implementation? Why not only write the necessary types?

Instead of this

abstract class A {public abstract int f(int x, int y);}
class B: A {public override int f(int x, int y) => x + y;}

Why isn't it just something like this?

abstract class A {public abstract int f(int, int);}
class B: A {public override int f(int x, int y) => x + y;}

Not to mention I seem to be allowed to name these identifiers in the abstract declaration whatever I like

abstract class A {public abstract int f(int a, int b);}
class B: A {public override int f(int x, int y) => x + y;}
Charlieface
  • 52,284
  • 6
  • 19
  • 43
GT 77
  • 448
  • 5
  • 12
  • If you don’t override the method then the variables will be called what you named them, therefore you’ll know you’re passing in x and y... – SomeDeveloper Apr 21 '21 at 21:05
  • An abstract class is designed to be able to be used by the consumer by itself. Therefore it is logical for the parameter names to be defined. But C# anyway needs to conform to .NET, which demands that a parameter name is defined, because of the logic above. – Charlieface Apr 21 '21 at 21:06
  • 2
    _"If I'm not going to implement the method, what's the point of giving arbitrary identifiers to the parameters?"_ -- lots of reasons, but one obvious one is that you can _call_ an abstract method, and C# has named parameters, so if you _name_ a parameter in the call, there has to be a way to know what _name_ to use. See duplicates for that and other reasons. – Peter Duniho Apr 21 '21 at 21:07
  • Minor point, SonarLint analyzers raises a warning if you change parameter names of overriden methods. – Alejandro Apr 21 '21 at 21:08

0 Answers0