Last active
November 8, 2020 22:40
-
-
Save MazizEsa/c898a3d5a5bb6cbc0fd2283c9651ee79 to your computer and use it in GitHub Desktop.
Incorrect Coupling
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
public class IncorrectCoupling { | |
public static class Points{ | |
private String productId; | |
private Long totalPoints; | |
private PointsMappingExternalSystem pointsMappingExternalSystem; | |
private PointsMultiplierExternalSystem pointsMultiplierExternalSystem; | |
public Double calculateTotalPoints(){ | |
return pointsMappingExternalSystem.getPointsMappingFromExternalSystem().stream().map(PointsMapping::getPoints).reduce(0d, Double::sum) | |
* pointsMultiplierExternalSystem.getPointsMultiplierFromExternalSystem().getMultiplier(); | |
} | |
} | |
public static class PointsMapping { | |
private String productId; | |
private Double points; | |
public PointsMapping(String productId, Double points) { | |
this.productId = productId; | |
this.points = points; | |
} | |
public Double getPoints() { | |
return points; | |
} | |
} | |
public static class PointsMappingExternalSystem{ | |
// contain logic to use http client / database client, get data and then map into objects | |
public static List<PointsMapping> getPointsMappingFromExternalSystem() { | |
// example | |
return Collections.emptyList(); | |
} | |
} | |
public static class PointsMultiplier { | |
private String id; | |
private double multiplier; | |
private LocalDateTime startDate; | |
private LocalDateTime endDate; | |
public double getMultiplier() { | |
return multiplier; | |
} | |
} | |
public static class PointsMultiplierExternalSystem{ | |
// contain logic to use http client / database client, get data and then map into objects | |
public static PointsMultiplier getPointsMultiplierFromExternalSystem() { | |
//example | |
return new PointsMultiplier(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment