Hi all,

We want to improve adding new dynamic properties to objects. I'm starting on 
this soon. Here are my thoughts so far…

I'm thinking the basic API will look something like this…

DynamicProperty newPropertyWithValue(String name, Object value)
DynamicProperty newProperty(String name, Action<DynamicPropertyBuilder> action)
DynamicProperty newProperty(String name, Closure<?> action)

The first form is for the most simple use case; adding a new property with a 
given name, no type and an initial value.

I'm thinking that for anything more complex we use a builder approach…

newProperty("foo") {
  type String
  value = "bar"
  transformer(SomeDomainObject) { it.toString() }
  validator { it == "bar" }
}

I haven't thought through that API at all, they are just wild examples. 
Initially DynamicPropertyBuilder wouldn't have much at all but we would evolved 
it over time.


Another question is where this API belongs. I can see 3 options…

1. mixed directly in to decorated objects (e.g. 
configurations.newPropertyWithValue("foo", "bar"))
2. added to ExtensionContainer (e.g. 
configurations.extensions.newPropertyWithValue("foo", "bar"))
3. added to obj.properties (e.g. (e.g. 
configurations.properties.newPropertyWithValue("foo", "bar"))

I think my preference is 1, but I'm worried about clashes and polluting the 
namespace.
2 is a little iffy, but has some appeal. It kind of fits under an “extension” 
namespace. It's more verbose than 1 though.
While 3 makes some sense, it's my least favourite. Adding these kinds of 
methods to a Map object seems dangerous.

All feedback appreciated as always.

-- 
Luke Daley
Principal Engineer, Gradleware 
http://gradleware.com


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to