Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Reuse code from Describe three params

The `describe(Character, Destination, TravelMethod)` method should reuse the logic implemented in `describe(Character)`, `describe(Destination)` and `describe(TravelMethod)`. Reusing existing methods can help make code easier to maintain.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Reuse code from Describe two params

The `describe(Character, Destination)` method should reuse the logic implemented in `describe(Character, Destination, TravelMethod)` or in the individual methods `describe(Character)`, `describe(Destination)`, `describe(TravelMethod)`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion for slight rewording and I don't think the describe(TravelMethod) is needed here.

Suggested change
The `describe(Character, Destination)` method should reuse the logic implemented in `describe(Character, Destination, TravelMethod)` or in the individual methods `describe(Character)`, `describe(Destination)`, `describe(TravelMethod)`.
The `describe(Character, Destination)` method should reuse the logic implemented in `describe(Character, Destination, TravelMethod)` or in the individual `describe(Character)` and `describe(Destination)` methods.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the describe(TravelMethod) is actually needed. In fact, the method describe(Character, Destination) can be implemented in two ways:

  1. public String describe(Character character, Destination destination) {
    return describe(character, destination, TravelMethod.WALKING);
    }

  2. public String describe(Character character, Destination destination) {
    return describe(character) + describe(destination) + describe(TravelMethod.WALKING);
    }

Without referring todescribe(TravelMethod), the student may think that one solution is also:

public String describe(Character character, Destination destination) {
return describe(character) + describe(destination) + "You're traveling to your destination by walking.";
>}

Also in design.md, they suggest to indicate it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, you're right! The describe(TravelMethod) is needed here.

Reusing existing methods can help make code easier to maintain.