Skip to content

Commit

Permalink
make LayeredArchitecture immutable
Browse files Browse the repository at this point in the history
For all properties except for `optionalLayers` we have followed the pattern of immutability, we should do the same here. Technically this is a breaking change, but since this immutability is the usual pattern that ArchUnit follows everywhere else, and the fluent API invites to simply chain these methods anyway, the risk is probably low.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
(cherry picked from commit 3e54892)
  • Loading branch information
codecholeric committed Feb 27, 2022
1 parent 246daae commit a755714
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static final class LayeredArchitecture implements ArchRule {
private final Set<LayerDependencySpecification> dependencySpecifications;
private final PredicateAggregator<Dependency> irrelevantDependenciesPredicate;
private final Optional<String> overriddenDescription;
private boolean optionalLayers;
private final boolean optionalLayers;

private LayeredArchitecture() {
this(new LayerDefinitions(),
Expand Down Expand Up @@ -140,8 +140,7 @@ private LayeredArchitecture(LayerDefinitions layerDefinitions,
*/
@PublicAPI(usage = ACCESS)
public LayeredArchitecture withOptionalLayers(boolean optionalLayers) {
this.optionalLayers = optionalLayers;
return this;
return new LayeredArchitecture(layerDefinitions, dependencySpecifications, irrelevantDependenciesPredicate, overriddenDescription, optionalLayers);
}

private LayeredArchitecture addLayerDefinition(LayerDefinition definition) {
Expand Down

0 comments on commit a755714

Please sign in to comment.