Method signature in Java:
public List getFilesIn(List directories)
similar one in ruby
def get_fi
Short answer: Automated unit tests and good naming practices.
The proper naming of methods is essential. By giving the name get_files_in(directory)
to a method, you are also giving a hint to the users on what the method expects to get and what it will give back in return. For example, I would not expect a Potato
object coming out of get_files_in()
- it just doesn't make sense. It only makes sense to get a list of filenames or more appropriately, a list of File instances from that method. As for the concrete type of the list, depending on what you wanted to do, the actual type of List returned is not really important. What's important is that you can somehow enumerate the items on that list.
Finally, you make that explicit by writing unit tests against that method - showing examples on how it should work. So that if get_files_in
suddenly returns a Potato, the test will raise an error and you'll know that the initial assumptions are now wrong.