Tuesday, 20 August 2013

Keep annotated clutter away from Domain Model

Keep annotated clutter away from Domain Model

I'm in the situation where I have a Domain Model that is clean. By clean I
mean it's just a collection of private properties and getter and setters.
I guess that's what's ment by the Anemic Data Model.
This model is interchangeable with other applications (can be shared with
other application code) without pulling in extra dependencies.
This model needs to be serialized to different data formats. For this I
can use a wide range of annotations that greatly simplify my life.
Only they pull in an extra set of dependencies in all the projects that
will share the domain model. I've read it's not advised to clutter the
domain model for such reasons and I could possibly land in a Jar Hell.
I could write a wrapper that is annotated and pass in the domain model in
the constructor and copy all the properties over to the annotated model.
This way I can happily use annotations while keeping a clean Domain Model
that will not enforce any extra dependencies.
This is not specifically about serializing your data model but about
adding extra functionality (for example through annotations) in your
Domain Model that enforces new dependencies.
How do you handle such use cases what's a safe way to handle this without
having to fear Jar Hell ?

No comments:

Post a Comment