We are trying to come up with fluent API for nested Object. Consider we have following three classes
Attribute : name : String Value : Object
Item : action : String attributes :
Order : action : String attributes : items :
Here we want to have fluent API which can help to build above Objects.
Now we need to have builders as follows:
Attribute Builder
AttributeBuilder.make().name().value().build();
Item Builder
ItemBuilder.make().action()
.attribute()
.name().value().build()
.attribute()
.name().value().build()
.build();
Order Builder
OrderBuilder.make().action()
.attribute()
.name().value().build()
.attribute()
.name().value().build()
.item()
.action()
.attribute()
.name().value().build()
.attribute()
.name().value().build()
.build()
.build();
We may later nest the Order Object in Some other object.
So is there any way to achieve such nested DSL building ?
Aucun commentaire:
Enregistrer un commentaire