Skip to content

Instantly share code, notes, and snippets.

Created December 20, 2020 09:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Article: Law of Demeter - company without division
class Company {
private List<Department> departments;
Map<DepartmentCode, BigDecimal> costPerDepartment() {
Map<DepartmentCode, BigDecimal> costPerDepartment = new HashMap<>();
departments.forEach(department -> {
DepartmentCode departmentCode = department.getCode();
BigDecimal employeesCost = department.getTeams().stream()
.map(Member::getCost).reduce(BigDecimal.ZERO, BigDecimal::add);
costPerDepartment.put(departmentCode, employeesCost);
return costPerDepartment;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment