samedi 20 janvier 2018

What is this ORM pattern called

I have been used to frameworks like JPA to do the object-relational mapping between database rows and Java objects.

However, in my company we use proprietary framework for ORM, which doesn't use entity classes to represent an entity but just a java.util.Map class with database column values mapped to their names.

Typically such a map works also as a model for the presentation tier to render the form. Posting the form again injects the parameters to the handler methods as a map. It is an old framework from early 2000's.

Even thought the use of maps over entity classes smells like obsolescent and an anti pattern, I actually like the "dynamic" nature of this model. You can easily add any data to the map in the business logic layer before map gets passed to the presentation tier, and it becomes part of the form with only changes to the template itself. It allows you to augment any entity with anything, if necessary. And this is ultimately useful, if you must for example show certain notification for a certain field under certain conditions. You just check the condition, add the notification to map if necessary, and in template render it if it exists in the map. If I used entity classes, I would have needed to refactor the entity class interface with an attribute, which is not even real attribute of the entity. The business logic is full of these special conditions and they are constantly evolving.

Is this dangerous thinking - am I falling for an anti pattern? Or is it justified to use this kind of pattern with complex business domains, and does this pattern have a name?

Aucun commentaire:

Enregistrer un commentaire