csharp-analyzer icon indicating copy to clipboard operation
csharp-analyzer copied to clipboard

Add feature for method overloading exercise

Open mikedamay opened this issue 4 years ago • 0 comments

See the method-overloading exercise.

The following feature should be added:

There are three overloaded Describe() methods which each take a single parameter (character, destination and travel method. They are not addressed by this issue.

In addition to the above 3 overloads the instructions require that the code should allow:

  • the caller to specify all 3 aspects in one call (character + destination + travel method).

  • or the caller to specify just 2 aspects, character and destination, in which case TravelMethod.Walking should be used as the travel method.

There are 2 ways for the student to approach this. Firstly, to include one overload with 3 parameters and a separate one with 2 parameters. In fact the boilerplate takes this approach.

public static string Describe(Character character, Destination destination, TravelMethod travelMethod) {}
public static string Describe(Character character, Destination destination) {}

The alternative is to omit the 2 parameter method altogether and give the final (TravelMethod) parameter of the 3 parameter method a default value of TravelMethod.Walking as is shown in the example code.

public static string Describe(Character character, Destination destination, TravelMethod travelMethod = TravelMethod.Walking) {}

The analyzer should report that the second approach, giving the parameter a default value, is preferable. This should also handle the case where named parameters are used.

mikedamay avatar Jun 16 '20 12:06 mikedamay