XmlObject - Adaptive Object Model

Better Designs Faster

WavePlayer Example

The WavePlayer is a very simple application that was conjured up for demonstration purposes.† To start the WavePlayer enter the following command at the CLI prompt.

†††††††††††††††† load WavePlayer

If you have defined the virtual drive as described on the download page, you can look at the application metadata by clicking here.† Otherwise navigate to the WavePlayer.xml file and open it in an editor.†

Notice the three commands, load, play, and stop.† The commands work exactly as you would expect.† The only one that is special is the play command.† It can play a file synchronously or asynchronously depending a command line switch.† If you play a file synchronously the application blocks until the sound stops.† Whereas if you play the file asynchronously you can stop it by entering the stop command.†

There are a few other things to notice about the metadata.† You can see the text for the window title bar is defined in the title element.† The string used for the prompt is defined in the prompt element.

It is time to better explain delegates.† I deferred discussion till now where we would have the context of an application to help the discussion make sense.† One might wonder why the delegates even exist.† I could have accomplished the same thing by defining multiple (uniquely named) command elements.† Mostly delegates exist to make it easier to create CLI based applications.† When in the R &D phase of development it is very convenient to be able to change behavior by switching delegates.† It is not full adaptive behavior but then neither does it have the complexity of a full Adaptive Object Model.

Delegates are derived from the abstract class CommandDelegate.† CommandDelegate is markedly simpler than XmlElement, making the job of writing a delegate easier.† There is only one CommandElement.† However, I am constantly creating new delegates derived from the CommandDelegate class.

Here is a class diagram showing the relationship between elements and delegates in the CLI project.

CLI Diagram

Notice how elements and delegates are related.† There is some fairly complex business logic that ties the two together.† Without delegates, developers would have to know about and understand this business logic.† Delegates hide this complexity and allow the developer to focus only on command implementation.

Here is another class diagram showing the structure of the WavePlayer.† The Application holds the reference to the object that does the actual work.† Notice that each command is derived from the abstract base class Command, and that Command is in turn derived from CommandDelegate.† Each command get access to the Application through its base class.† The full WavePlayer development was completed in about 30 minutes.† It took longer to come up with the idea then it did to implement it.

WavePlayer Diagram

I have used this technique with great success in other, more complex applications.† It works well when you need some flexibility, but donít want to overly complicate things.

XmlObject Graphic