开发者

How many data object layers is a good practice?

开发者 https://www.devze.com 2023-02-19 00:56 出处:网络
We have a medium 开发者_C百科sized Java server that has data flowing in the following way: SQL Database -> Data Layer -> Business Layer -> XML Serialization

We have a medium 开发者_C百科sized Java server that has data flowing in the following way:

SQL Database -> Data Layer -> Business Layer -> XML Serialization

It's important to note, that the data model mostly does not change between the layers. Yet I have been told that having a single data model used as: SQL Database -- (IBATIS) -> Model -> convert the model to XML - is not a good idea, since schema changes mean changes in the model and then change in all layers in the application. And XML changes also mean the model has to change.

So is it recommended to have two object layers in this case? 1) Business logic data layer that the business schema maps to using IBatis. 2) XML layer that JAXB uses to convert to XML.


Note: I lead EclipseLink JAXB (MOXy), and EclipseLink provides both JAXB and JPA implementations.

I recommend using one data model that is mapped to XML via JAXB, and to the database via JPA.

schema changes mean changes in the model and then change in all layers in the application.

  • If the schema change introduces new data then it does affect the model, schema changes that do not introduce new data (change element ordering, add a grouping element) should only affect the mapping metadata.

So is it recommended to have two object layers in this case?

  • If you have two object models then you are going to introduce a layer that converts between the object models. This involves another library you need to deal with, and more code that you need to maintain. A change to your schema now affects your object model, and your object conversion layer. This is a similar impact to the one object model scenario.


In general: yes, it's better to have a separate models.

P.S. Since in your question you called it layers, you may like the following cartoon: http://geekandpoke.typepad.com/geekandpoke/2011/03/architectural-best-practices.html Don't take it too seriously :)

0

精彩评论

暂无评论...
验证码 换一张
取 消