Skip to content

Instantly share code, notes, and snippets.

@pawelpluta
Last active December 20, 2020 11:02
Show Gist options
  • Save pawelpluta/968b1f16545d45f73f11d6195b915095 to your computer and use it in GitHub Desktop.
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