The first approach seems cleaner. Provides additional information. People reading the code will immediately recognize the meaning of the code, which is important when debugging or maintaining another user's code.
Here are two examples that are close to what you are doing from 2 of the best developed frameworks:
Jdk7
package java.security.acl
public interface Group extends Principal
{
public boolean addMember(Principal user);
public boolean removeMember(Principal user);
public boolean isMember(Principal member);
public Enumeration<? extends Principal> members();
}
Spring:
public interface GroupManager {
List<String> findAllGroups();
List<String> findUsersInGroup(String groupName);
void createGroup(String groupName, List<GrantedAuthority> authorities);
void deleteGroup(String groupName);
void renameGroup(String oldName, String newName);
void addUserToGroup(String username, String group);
void removeUserFromGroup(String username, String groupName);
List<GrantedAuthority> findGroupAuthorities(String groupName);
void addGroupAuthority(String groupName, GrantedAuthority authority);
void removeGroupAuthority(String groupName, GrantedAuthority authority);
}
As you can see from these interfaces, if I were reading the code, you could immediately say what the code does, without returning and without looking at the type of object.
I will vote for your example A. It just makes everyone live easier.
source
share