views:

53

answers:

2

Hey guys,

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 models 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

A: 

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 shown that there is no general solution.

Stephen C
A: 

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

This article goves a good overview on developerworks

crowne