Created
April 25, 2011 12:20
-
-
Save gunnarmorling/940438 to your computer and use it in GitHub Desktop.
HV-431: New approach by removing creational context from ConstraintDef completely
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
ConstraintMapping mapping = new ConstraintMapping(); | |
mapping.type( Marathon.class ) | |
.property( "name", METHOD ) | |
.constraint( new SizeDef() | |
.message( "name too short" ) | |
.min( 3 ) ) | |
.constraint( new NotNullDef() ) | |
.property( "numberOfHelpers", FIELD ) | |
.constraint( new MinDef().value( 1 ) ); |
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
ConstraintMapping mapping = new ConstraintMapping(); | |
mapping.type( Marathon.class ) | |
.constraint( GenericConstraintDef.from( MarathonConstraint.class ) | |
.param( "minRunner", 1 ) ) | |
.property( "name", METHOD ) | |
.constraint( new SizeDef() | |
.message( "name too short" ) | |
.min( 3 )); |
Hmmm, people still could keep such references, I don't think there is a way to avoid this. Alternatively one could also have the create method on ConstraintDef instead:
ConstraintMapping mapping = new ConstraintMapping();
mapping.type( Marathon.class )
.constraint( ConstraintDef.createGeneric( MarathonConstraint.class )
.param( "minRunner", 1 ) )
.property( "name", METHOD )
.constraint( ConstraintDef.create(SizeDef.class).message( "name too short" ).min( 3 ) )
.constraint( ConstraintDef.create(NotNullDef.class )
.property( "numberOfHelpers", FIELD )
.constraint( ConstraintDef.create(MinDef.class).value( 1 ) );
That way there is one entry point for instantiating constraint definitions and the creation of "normal" and generic constraint definitions would be somewhat unified. But actually I don't have a strong preference here. I think I'd go for the last version but if you guys team up for one of the other solutions I'm fine with any of them either :)
Sure, we cannot prevent it, but I have the "feeling" it is less likely this way :-)
I actually like the ConstraintDef.create better. It might be a little longer, but it seems indeed more unified.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WDYT about this:
not having the new constructor might also minimize the risk that people keep references to the instantiated def classes