-
-
Save pawelpluta/968b1f16545d45f73f11d6195b915095 to your computer and use it in GitHub Desktop.
Article: Law of Demeter - company with instanceof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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