开发者

Data Model Evolution

开发者 https://www.devze.com 2023-01-02 05:20 出处:网络
When writing code I am seeing requirements to change data models (e.g. adding/changing/removing data members from a class). When these data models belong to an interface, it seems difficult to change

When writing code I am seeing requirements to change data models (e.g. adding/changing/removing data members from a class). When these data models belong to an interface, it seems difficult to change without breaking the existing client codes. So I am wondering if there is any best practice of designing interfaces/data mode开发者_C百科ls in a way to minimize the impact during evolution.

The closest thing I can find from google is data contract versioning. But that seems to be a .net specific topic. I am wondering if the same practice applies to the Java world, or there is a different or generic way to deal with data model evolution.

Thanks


There are some tools which can help, have a look at LiquiBase.

This article goves a good overview on developerworks


There are no easy answers to this in either the Java or data modeling domains.

  • Some changes are upwards compatible; e.g. addition of new methods, optional fields, subclasses and so on.
  • Some changes are not compatible, but can be handled using a simple transformation; e.g. addition of a mandatory field could supported by a transformation that adds an extra constructor argument.
  • Some changes unavoidably require major programmer intervention.

Another point to note is that the problem gets a lot harder when the data corresponding to the data models is persistent, and cannot be thrown away when the data model changes. This is referred to as the "schema evolution" problem, and I believe that it has been proven that there is no general solution.

0

精彩评论

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