Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature for method overloading exercise #52

Open
mikedamay opened this issue Jun 16, 2020 · 0 comments
Open

Add feature for method overloading exercise #52

mikedamay opened this issue Jun 16, 2020 · 0 comments

Comments

@mikedamay
Copy link

mikedamay commented Jun 16, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant