About Models

In this set of posts when I talk about model I mean the Model component of Model View Controller.

Recently I have been working on a Model/Business Rule engine.

A lost of people that implement MVC or MVP tend to use the Model component as a simple data container with methods.  This does not keep the model as powerful or flexable as possible.

The Model can be used to validate a set of data.  For example we have a utility (in about 20 lines of code) that loops through our database and reports all of the validation faliures.

In order to validate data the model must be able to be populated with invalid data (or null data).  This means thatlanguage type systems are not sufficient.  We developed our own abstract type system in which any type can be supplied a string value. Integers set to XXX are not valid, but at least the model can report this.

Our model forms a tree of composite objects. Business rules are attached to these objects.  The composite supports XPath querying so that our business rules can be robust with respect to changes in the model structure.  We implemented an XPathNavigator descendant to provide this functionality.  Our composite objects have “attributes” (not in the C# sense of [XXXAttribute])  that use our model types.