Fluent Interface – A technique for handling a constructor with a great many parameters. You chain together setter methods that return the object. This gives the effect of keyword=value. The catch is, the constructor can’t ensure consistency before the object is constructed. (source)
Joshua Flanagan has built ‘ReadableRex‘, your ‘fluent interface’ into Regular Expressions. [Joshua's post]
His example walks you through creating a social security # pattern:
Regex socialSecurityNumberCheck = new Regex(Pattern.With.AtBeginning
.Digit.Repeat.Exactly(3)
.Literal(“-”).Repeat.Optional
.Digit.Repeat.Exactly(2)
.Literal(“-”).Repeat.Optional
.Digit.Repeat.Exactly(4)
.AtEnd);
Thanks for the mention, but you copied the wrong code sample
The SSN check was the first example – a much simpler pattern.
Comment by Joshua Flanagan — October 26, 2006 @ 10:38 pm