Skip to content

Instantly share code, notes, and snippets.

@pawelpluta
Last active December 20, 2020 11:02
  • 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
Save pawelpluta/968b1f16545d45f73f11d6195b915095 to your computer and use it in GitHub Desktop.
Article: Law of Demeter - company with instanceof
class Company {
private List<Department> departments;
Map<DepartmentCode, BigDecimal> costPerDepartment() {
return departments.stream()
.filter(this::costCenter)
.collect(Collectors.toMap(Department::getCode, Department::cost));
}
private boolean costCentre(Department department) {
return department.getType() instanceof CostCentre;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment