Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. Map<Group, Map<Username, GroupMember>> groups
  2.  
  3. public class Foo {
  4.  
  5. private final Map<Group, Map<Username, GroupMember>> groups;
  6.  
  7. //...
  8.  
  9. public void addGroup(Group group) {
  10. if (exists(group))
  11. throw new IllegalOperationException("Group with same name already exists");
  12. //Declaring a new HashMap within the class (i.e. defining the implementation within a class member)
  13. groups.put(group, new HashMap<Username, GroupMember>(Map evaluation based on group object)));
  14. }
  15.  
  16. //...
  17. }
  18.  
  19. //Passing Map<Username, GroupMember> object decreases abstraction and exposes implementation details
  20. public void addGroup(Group group, Map<Username, GroupMember> groupMembers) {
  21. if (exists(group))
  22. throw new IllegalOperationException("Group with same name already exists");
  23. groups.put(group, groupMembers));
  24. }
  25.  
  26. public class Group {
  27.  
  28. private final String name;
  29. private final String description;
  30. private final Instant dateCreated;
  31. private final Collection<GroupMember> members;
  32.  
  33. //... Constructor and getters for the fields
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement