MetaBuilder offers a number of features that make creating and using new builders safer and easier. First and foremost, it lets you specify your builder using a simple build language with lots of functionality to validate and control how objects are built.
Here's a Groovy script example to give you the flavor of it:
import groovytools.builder.*
MetaBuilder mb = new MetaBuilder()
mb.define {
customer {
properties {
name(req: true)
age(check: 1..120)
sex(check: ~/M|F/)
}
}
}
def aCustomer = mb.build {
customer(name: 'J. Doe', age: 25, sex: 'M')
}
If you manage to mistype a property name or violate a check constraint, MetaBuilder will throw an exception.
No comments:
Post a Comment