java - Domain Objects to map -


we building micro-service rest api in groovy part of more complex application. service simple crud operations.

we using groovy , on need pull record database ( mongodb ), , return object after changing format of fields ( backward compatibility ), on these lines:

def object = collection.findone(query) object.field3 = object.field2.collect { [..]} return object 

i not experienced in groovy or java ( worked more extensively on ruby/python/clojure ), have domain object:

class foo {   string _id   string field1   array field2     map tomap() {        [field1: field1, field3: field2.collect {}, field2: field2]   } } 

and go

foo = new foo(objectmapfromdb) foo.tomap() 

and of benefits see using approach can @ domain object , have idea of structure of object in database is, can type safety if want more importantly ( , that's drove decision ) code converting map encapsulated in function , can re used in other part of project

a more senior developer questioned approach mentioning yagni , stating domain objects complex, , reverted changing changing map above.

i bit puzzled, tried around information avoiding domain objects can't find similar ( have looked @ anaemic domain model, seems take extreme ). yagni don't feel applies in case.

i don't see terribly wrong that, simple application seems fine solution, novelty of approach stimulate curiosity.

any thought on this? missing something? thanks


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -