Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Adaptive Java applications -- XML makes it possible

Create an adaptive, dynamic, and extensible messaging system using Java, XML, and the DOM

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
In the history of programming languages there has been a discernable movement towards the componentization and modularization of program behavior. The advent of object-oriented programming has allowed applications to make use of components and to define the relationships between them.

However, object-oriented applications still view and deal with data as an intrinsic part of the component (object). This can be harmful for all but the simplest applications. For example, if an object is coded to expect a certain data flavor, say account_number, recalibrating that object to expect a different flavor can be tedious work.

It would be convenient to be able to set an object's state at runtime so that it deals only with the behavioral aspects of the application (performing some mathematical operations on the data, for example). However, in such a situation, the notion of type-safety could be compromised -- if everything can legally be passed to the object's state, runtime type checking becomes pointless.

With the introduction of XML and its subsequent adoption by the major players of the software industry, data can lead its own life. An XML document is, in many ways, a database, a fact that can be exploited to build adaptive systems. In an adaptive system, careful design thought is given to isolating objects from one another and isolating data from the behavior (for example, the operations and methods) defined in the object.

To demonstrate how this works, we will design a simple messaging system that hides the communicating objects from one another and holds the data manipulated by the objects in a parallel universe -- as XML.

(To download the complete source code for this article's messaging system, see Resources.)

Adaptive systems

You can classify an adaptive system by the degree of independence its code has from data and by its resilience to change. The greater the independence and resilience, the more adaptive the system is said to be. It has long been an acknowledged shortcoming of conventional object-oriented programming that data is too tightly hard-coded into the design and implementation of objects. As a result, adaptivity is a necessary next step in software engineering.

Indeed, applications need to be able to communicate with and adapt to one another -- transparently. Moreover, compound applications (especially distributed ones) need to be designed to anticipate change -- change in their components and in the way these components interface with other applications.

On the other hand, object interrelationships should also be transparent. Objects need to rely as little as possible on one another's existence to perform their tasks. Different approaches have been proposed over the past decade to come up with an alternative to conventional object-oriented practices. Arguably, the most prominent alternative is the Demeter method, which defines strategies for an object-graph traversal (see Resources for more on the Demeter method). However, although the Demeter method defines rules for building adaptive object-oriented applications, it does not specifically concentrate on the independence of data from behavior.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources