Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Map<Group, Map<Username, GroupMember>> groups
- public class Foo {
- private final Map<Group, Map<Username, GroupMember>> groups;
- //...
- public void addGroup(Group group) {
- if (exists(group))
- throw new IllegalOperationException("Group with same name already exists");
- //Declaring a new HashMap within the class (i.e. defining the implementation within a class member)
- groups.put(group, new HashMap<Username, GroupMember>(Map evaluation based on group object)));
- }
- //...
- }
- //Passing Map<Username, GroupMember> object decreases abstraction and exposes implementation details
- public void addGroup(Group group, Map<Username, GroupMember> groupMembers) {
- if (exists(group))
- throw new IllegalOperationException("Group with same name already exists");
- groups.put(group, groupMembers));
- }
- public class Group {
- private final String name;
- private final String description;
- private final Instant dateCreated;
- private final Collection<GroupMember> members;
- //... Constructor and getters for the fields
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement