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

strain: include hints to explain why methods are static #367

Closed
jtigger opened this issue Mar 8, 2017 · 3 comments
Closed

strain: include hints to explain why methods are static #367

jtigger opened this issue Mar 8, 2017 · 3 comments
Labels
code good first issue Good for newcomers

Comments

@jtigger
Copy link
Contributor

jtigger commented Mar 8, 2017

As per #177, we prefer using instance methods over class methods (see discussion in that issue for rationale).

However, there are conditions in which it is absolutely appropriate for a function to be static. A common situation is because the function is effectively an extension of an existing type — you are defining behavior you wished were defined on a given type.

Since classes in Java are closed for modification (i.e. you cannot add members to a class outside its definition like you can in other languages like Ruby or JavaScript), you cannot add the new behavior to the class, directly. The idiomatic solution in this case is to write a utility method.

Collections of these kinds of methods are often referred to as "utility classes". Examples of such classes from within the JRE include Arrays and Collections.

In the case of the exercise strain, we "wish" that List had keep(), discard(), and filter() methods on it. It doesn't, so we're including them here.

Please include a HINT.md file in strain that points out that these methods are static and capture the description above, in your own words as to why this class has this shaped API.

@jtigger jtigger added code good first issue Good for newcomers labels Mar 8, 2017
@stkent
Copy link
Contributor

stkent commented Mar 8, 2017

Reminder that strain is in the process of being deprecated in favor of list-ops

@jtigger
Copy link
Contributor Author

jtigger commented Mar 8, 2017

Awwww geez! Thank you, @stkent! :) I'll close this and create a new one for that exercise.

@jtigger jtigger closed this as completed Mar 8, 2017
@stkent
Copy link
Contributor

stkent commented Mar 8, 2017

Perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants