I was reading here about OOP and methods, and the accepted answer states that method names should be verbs. However, that doesn't really answer my question.
Suppose if I had a Character class with a private List inventory.
public class Character {
private List<GameItems> inventory;
// constructor and other methods left out.
public boolean checkInventoryfor(GameItem item)
}
Now, suppose at various points in my game, the player wants to check their inventory for a specific item, the checkInventoryfor(GameItem item) can be called.
I've been told that the name is a code smell, because it gives away the fact the class has a collection (inventory) that needs to be checked. A better name would be has(GameItem item). has() flows better in terms of language because most likely you'll have an if statement that reads if(character.has(sword)) {// rest of code here}.
Either way, you know that you're querying a collection, of what type? We don't know, we don't care. Neither method tells you, all it returns is a boolean.
Can method names leak implementation details and break encapsulation?