Data binding makes use of object-oriented programming's primary strength -- the ability to encode data and operations (functions, methods, behaviors) in the same structure. It is that mechanism that allows the Book object, for example, to include the code necessary for automatic data validation, as well as the code used for marshalling and unmarshalling.
In general, data binding will generate the majority of the code that a developer would want to include in the data objects. In some cases, though, a developer may want to add additional code to the generated classes.
In particular, the ability to add code to the generated classes makes it possible to take advantage of polymorphism. For example, the Book class might have a placeOrder() method that sends messages to one warehouse in blocks of 1,000, while the same method for the CD class prints out an invoice that can be FAXed to a 3rd party shipper. Ideally, the application wants to ignore such differences and simply invoke the placeOrder() method, without having to care whether it is dealing with a Book or CD.
Polymorphism makes it possible for an application to do that. For example,
Book and CD could both be subclasses of an OrderableItem
class. The application can process the list of OrderableItem objects
in the order, invoking the placeOrder() method on each one, not caring
whether any particular item was a Book or a CD.
There may be other reasons to add code, as well. The nature of such code would of course depend on the application, but there is usually a reason to add some code. Of course, you could always add code manually, but then it would be lost if you recompiled the schema.
One possible approach is to allow the developer to extend the classes generated by the schema compiler. If the compiler generates the Book class, for example, the developer might extend it to create MyBook. In this scenario, the generated classes would use a dispatch table to make sure the marshalling and unmarshalling code uses the extended classes, rather than the original classes.
Note:
Similarly,MyCDwould extend the generatedCDclass. If both subclasses implemented anOrderableIteminterface, then the placeOrder() method could be invoked polymorphically on theOrderableItemobjects, without regard to whether they were books or CDs.
Other approaches are under consideration, as well. For example, the schema compiler might generate a combination of classes and interfaces. The work is in its early stages, so it is not clear which option will maximize development flexibility and runtime performance. Whatever the eventual design, though, one thing is certain: Data Binding will deliver high performance applications with a minimum of development effort, and retain all the advantages of doing Object-Oriented development on the Java platform.