Skip to content

use some kind of pair to define layeredArchitecture. #1534

@xenoterracide

Description

@xenoterracide

I'd like a pair or record defined around layeredArchitecture. I'm certain that when you made the DSL that you assumed manual formatting. Every formatter I know deals with the chain as each method on seperate lines.

I've now written this record

record Layer( String name, DescribedPredicate<JavaClass> predicate ) {}

Instead of writing

layeredArchitecture()
   .layer("A")
   .definedBy(residesInAPackage("...")
   .layer("B")
   .definedBy(residesInAPackage("...")
   .layer("C")
   .definedBy(residesInAPackage("...")
   .layer("D")
   .definedBy(residesInAPackage("...")
   .layer("E")
   .definedBy(residesInAPackage("...")
   .layer("F")
   .definedBy(residesInAPackage("...")
   .whereLayer("A")
   .mayNotAccessAnyLayer()
   .whereLayer("B")
   .mayOnlyAccessLayers("A")

which ultimately becomes an unreadable mess... I'd rather write

layeredArchitecture()
   .layer(new Layer("A", residesInAPackage("..."))
   .layer(new Layer("B", residesInAPackage("..."))
   .whereLayer("A")
   .mayNotAccessAnyLayer()
   .whereLayer("B")
   .mayOnlyAccessLayers("A")

How I would really want to write this though is

var a = new Layer("A", residesInAPackage("..."))
var b =new Layer("B", residesInAPackage("..."))

layeredArchitecture()
   .layer(a)
   .layer(b)
   .whereLayer(a)
   .mayNotAccessAnyLayer()
   .whereLayer(b)
   .mayOnlyAccessLayers(a)

or really

static class Domain {

   static DescribedPredicate<JavaClass> AGGREGATE = residesInAPackage("domain.aggregate.(*)")
   static DescribedPredicate<JavaClass> SERVICE = residesInAPackage("domain.service")

   static Layer layer() {
     return new Layer("Domain", or(AGGREGATE, SERVICE);
   }
}

layeredArchitecture()
   .layer(Domain.layer()) // note: layer is a value object and thus any instance with the same value...

this reads cleaner, forces static typing vs less string constants, and my rules are more complex than just resindesInAPackage hence not asking the second for a String or String.... A record is not required, that's just my implementation of a wrapper here.

given this is low hanging fruit. I would consider creating a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions