XmlObject - Adaptive Object Model

Better Designs Faster

Adaptive Object Models

So, what is an Adaptive Object Model?† As often as Iíve heard the question, I do not have a simple answer.† Like many things technical, it is not easy to give a quick answer.† More often than not quick descriptions miss, eyes glaze over and nothing gets accomplished.

For many development efforts there is little need to go beyond the static or dynamic models previously described.† On the other hand, it is quite easy to construct realistic examples where the previously described dynamic object model would not work.† For example, what do we do if someone asks to model an electric car, or even more challenging, a hybrid vehicle with two motors?†† Were this the case I hope it is apparent that the previous model is not adequate.

This is where the adaptive object model becomes useful.† Note that in the dynamic model we can only specify the number of cylinders.† The basic fact that engines have cylinders is still statically encoded in the model.† What if an engine didnít have cylinders but instead had chambers as did the rotary engine invented by engineer Felix Wankel.† It is still an internal combustion engine much the same as our piston engine, and for the most part our existing object model is entirely appropriate.† What is called for is a model that is more adaptive.† Instead of hard-coding object relationships in source, we would instead create a small database (meta-data) that describes the object model you intend to create.† The object model is then created at run time by an object model factory using the information in this database.† This entails a small amount of work that must be done up front and before work commences on the real model.† However, once this work has been done, many things become possible that are impossible (or at the very least, difficult) using static or dynamic object models.† What I am promising is possible because we can change the object model at runtime by simply changing the meta-data.

To continue on with an example, say you wanted to build an engine analysis tool that could handle all of the variations thus far described, and maybe some that havenít been described.† Based on my limited understanding of automotive technology, at a minimum we should expect motors that use electricity, ethanol, petroleum/ethanol mixtures and possibly hydrogen.† Some of these cars will use batteries, some fuel cells and others will have hybrid power plants.† The obvious point is that we do not know what changes are coming.† Getting back to modeling issues, this is going to be a difficult problem to model regardless of the object model philosophy.†

Now, we are right at the point where my attempts to explain adaptive object models usually derail.† In a perfect world I could show you another diagram and it would put all this object model nonsense in perspective.† The truth of it is that static diagrams are not all that useful for conveying information that is essentially dynamic.† I could show you a model of an adaptive object model object, but I am not at all certain it will answer your questions.

Static Object Model

Figure 4: Adaptive Object Model Object

 

The object in this diagram has a field that defines the name of the object, and fields (represented as associations) that show the relationship to itís parent and to any children.† My experience is that most do not find much value in the above diagram.† I believe that this is because it lacks the implicit context of a static object model.† However, I have also been told that it is useful.† I will presuppose that oneís degree of comfort is directly related to oneís familiarity with Adaptive Object Models and oneís level of comfort with abstractions.

If you are like me perhaps it will help to point out that, when instantiated, adaptive object models look very much like our earlier static models.† Here is the dynamic model from above, as if it were rendered from meta-data and reworked to be adaptive.

Piston Engine

Figure 5: Adaptive Object Model from Meta-Data

Again we have a diagram modeling a Car that has an Engine and the Engine has a collections of Cylinders.† Each of these has been derived from our Object base class.† Storage for the Parent and Children fields is maintained in the base class.† Derived classes implement properties (syntactic sugar) that cast the type of the base class fields to the appropriate derived type.† In addition, notice that the Engine, Cylinders, and Cylinder classes each define an associative property that points to the parent object.† This also is a bit of syntactic sugar that facilitates type conversion.†

Now, finally we get to the adaptive part.† Lets say that we need to switch from an ordinary piston engine to a rotary Wankel engine.† What need to change?† Obviously the metadata behind the object model need to change.† We need to instantiate a different kind of Engine as is done if Figure 6.

Wankel Engine

Figure 6: Adaptive Object Model w/Wankel

This Engine has Rotors instead of cylinders.† The derived classes implement different associative properties that cast base class storage to the appropriate type along with other behaviors that would be appropriate for a rotary engine.

It is possible to take this one step further.† In the above examples the object model is created at runtime.† However, the definition of the derived classes was done exactly as we would do it were this a static object model.† This makes it much easier to define custom behavior in derived classes.† However, there is nothing to stop us from defining derived class behavior dynamically also.† It is more work, but easily within our capabilities.† For some problems, in some domains, the additional flexibility would be well worth the cost.† For example, one could design a very low cost and flexible rules engine as is commonly being done for health care, banking, and insurance businesses these days.

I hope that I have adequately explained what an adaptive object model is.† As I stated earlier, I struggle with this.† It seem to me that tools at our disposal fall just short of what is needed† to truly do a good job.† I suspect that were adaptive object models to grow in popularity this problem will become less of an issue.

XmlObject Graphic