Skip to content

Instantly share code, notes, and snippets.

@pawelpluta
Created December 20, 2020 11:04
  • 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
Embed
What would you like to do?
Article: Law of Demeter - company with costCentre
class Company {
private List<Department> departments;
Map<DepartmentCode, BigDecimal> costPerDepartment() {
return departments.stream()
.filter(this::costCentre)
.collect(Collectors.toMap(Department::getCode, Department::cost));
}
private boolean costCentre(Department department) {
return department.isCostCentre();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment