I spent a long time during the last months writing about meta-models. That was in the context of a book for Editions ENI (France) about some concepts to which I dedicated some work since quite a while (it was around 1998, as long as I remember, that I started studying the basis of the approach).
In previous posts (see, for instance, Silverlight database to DataGrid, yet another approach- Part II) I exposed a generic approach for describing database meta-data. The direct practical purpose of those posts was reading and displaying data into Silverlight DataGrid. Through this exercise, we also saw how can our structures help us in integrating business rules at several level (meta-column, meta-table… and so on).
In this same exercise, applying the meta-models approach would consist of persisting these structures into the database… to read and create them dynamically.
We would, for instance, store our meta-columns / meta-tables definitions into the database and let our software objects load these structures and transform them into ‘live’ data, integrating all defined business and technical constraints.
I use the term "meta-model" to designate "a description of a description" stored in a database and interpreted (read and presented) by one or more (specific) software objects (classes).
That is: the information stored in the database describes an object or a behavior, and the software class that reads this information is aware of the fundamental semantics of this information and is, thus, able to interpret it independently of a particular context.
This means that, according to our view, a meta-model is composed of:
§ Database objects and structures to store the model's data;
§ Software (kernel) objects that know the fundamental semantics of the database model.
The collaborative aspect between the 'description' stored in the database and the 'runtime object' (which reads and interprets that description) is essential for this approach to be applicable.
Let us take a sample application where the software should display a page (or form) composed of a Master / Detail connected regions… i.e. a list of items in a Master grid, with a Detail form that displays the details of the item selected in the Master grid.
That 'Master/Detail’ layout may be the software application's approach for presenting the information of several entities. The application developer may choose to create a specific page for each manipulated entity… a choice which may be correct in some contexts, but which also remains questionable by its repetitive approach.
In another, more automated, approach, the software developer may prepare templates for each entity's specific Master/Detail information, and load the required template according to the context's entity.
This latest approach would be a first step for a meta-modeling approach for entities' presentation.
In fact, storing these templates as part of software objects would make them dependent of their related objects' compiled state. That is: the template cannot evolve without changing and recompiling related objects' code. Storing template's information in a database (meta-model) would circumvent this inconvenience.
In the same time, storing templates' information in a database would also require a (more or less important) change in software object's structure and behavior. Using a database meta-model approach (to describe Master/Detail templates in our case), requires the software object to act in a more abstract way. And this is what we called 'collaborative' approach (between database meta-model and runtime objects).
Finally, in the long run, our software object would constitute a 'kernel object' capable of displaying and handling any entity's Master/Detail information stored in a database meta-model.
The sample exposed above can of course be extended to more elaborate models and interactions between descriptions stored in a database and their software objects' counterpart.
Let us again take another practical sample: an application that may need to normalize the appearance of asp.net data grid controls.
We know that a GridView control contains some appearance properties like:
§ … etc.
We may choose to use the database to store values for each of these properties and let our software objects assign these values to each DataGrid (on the page's load event for instance).
Now, to handle the appearance of our GridView controls, we just need to assign new values for these properties in the database. A task which requires less effort, less time and fewer technical skills.
Reflection is the process of introspection (self-examining) of the internal structures of software objects at runtime. .NET implements Reflection in some classes defined in the System.Reflection namespace.
Our previous exercise can be extended to more abstract and useful applications.
In fact, a software object (like GridView in the last sample) has properties to which we can dynamically assign values if we may simply know their name:
PropertyInfo property = Type.GetProperties().FirstOrDefault(
p => string.Compare( p.Name, my_name) == 0);
After locating the property inside the specified object's Type (class) we may assign it a specified value:
Our meta-model may make use of Reflection mechanisms to store property names and values in the database, to read and assign the specified values to the specified objects at runtime.
This approach may be of interest in many software applications. Its main advantages are, again:
§ More adaptable and versatile software;
§ Reducing development and maintenance efforts, time and cost!
What we explained above about using System.Reflection to discover an object's property by name and assign a value to the retrieved property, is also applicable to methods:
MethodInfo method = Type.GetMethods().FirstOrDefault(
m => string.Compare( m.Name, my_name) == 0);
method.Invoke( … )
On the other side, user interface’s command elements like Menus, buttons… are often associated with an event handler that represents the entry point for the action of the command.
To explain how a meta-model can be useful in this area, let us take an example of an update button.
An update button collects the user entries into the form fields, checks their integrity and submits them to the server for updating the specified table;
Having the meta-data and business rule constraints for the columns of the entity, this update operation can be handled through one same handler. Or be handled by a dynamically selected handler specific to the context.
So, we know that a data entry form would have an update button. And we may need to assign a specific method as the handler of the Click event for this button.
All these required information elements can be stored into a database meta-model. The meta-model software would then:
§ Read (or otherwise find) the name of the method assigned as handler of the button's action event;
§ Dynamically locate the method in the software (loading the assembly when required);
§ Invoke the method.
Again, this meta-model solution can be applied on different contexts (records submission, web service operations invocation… etc.) and/or on different objects or controls (buttons, menus… etc.).
The database meta-model approach may also be used in a way similar to what we already use in Interop assemblies (which create links between 'unmanaged / native' code end 'managed code').
A meta-model-aware assembly method may, for instance, prepare entries to methods that reside in non-meta-model-aware assemblies or methods.
Such methods can also be defined in different projects independent of the 'meta-model-kernel' assembly. And may, thus, allow a high level integration of existing applications (or data) into the meta-model solution.
As we said above, the meta-model as exposed in this paper, is a collaborative ensemble where the database descriptions are tightly connected to the meta-model kernel software.
Two more questions though:
§ What about the evolution of the meta-model's own kernel?
§ How to describe objects that we don't yet know about?
Here comes another important point which seems to represent a good basis for answering the above questions:
§ An object is represented by a set of properties;
§ A property is, essentially, a definition composed of
· A Name
· And an Attribute (the Attribute defines property's constraints: mainly 'Data Type');
§ A Value can be assigned to a property in the context of either a class (static property) or to an instance of this class. (Note: Value should conform to the attribute's constraints).
So we may consider the data of an object as a collection of (Property / Value)… i.e. a collection of ((Name/attribute)/Value).
This seems to be, more or less easily, presented in a meta-model, which may allow us to handle future 'unknown objects' or future unknown 'properties'.
On one hand, meta-models are data stored in a database… and on the other, they are extensible. Managing them can also be described by meta-models. This recursive aspect can be of interest to some applications to allow users to autonomously manage software semantic behaviors without the need of extensive technical knowledge.