Modelling with Essential

After presenting the metamodel DSL, today is the turn for the modelling DSL.

As commented previously, Martin Thiede has a nice prototype called Concrete of a Web editor for model and metamodels. Such work and video also helps to understand the modelling and metamodelling duality.

Coming back to Essential, our tool is also providing a DSL to instantiate a metamodel. But a sample will probably be more illustrative:

Suppose the following simple metamodel:

namespace Core.Class
{
    class ClassModel
    {
        composition List<Class> Classes opposite Model;
    }
    class  Class
    {
        string Name;
        composition List<Attribute> Attributes;
    }
    class Attribute
    {
         string name;
         string Type;
    }
}

You could consider it as a very basic OO model. Intentionally I haven’t added too many details to keep it simple.

If you continue building it; adding operations, arguments, association support and more… at the end, you can have a metamodel comprising a full class diagram of UML, for example. The complexity of the metamodel you want to use is up to you. Having the control of the concepts inside the metamodel you can always add or remove features.

Modelling tools focused in UML, for example, provides this metamodel closed. You can’t change it, it’s a hard-wired standard and you are not allowed to change the core directly (only by extensions points like stereotypes and profiles).

Modelling Language

Now, let’s see how we can create a model using the previous metamodel:

using Core.Class;
namespace MyModel
{
    ClassModel  myClassModel
    {
        Classes = [Customer, Invoice];
    }
    Class Customer
    {
        Name = "Customer";
        Attributes = [Name, Surname];
    }
    Attribute Name
    {
        Name= "Name";
        Type= "string";
    }
    Attribute Surname
    {
        Name= "Name";
        Type= "string";
    }
    Class Invoice
    {
        Name = "Invoice";
        Attributes = [
            Attribute Amount
            {
                Name= "Amount";
                Type= "decimal";
            },
            Attribute InvoiceDate
            {
                Name= "InvoiceDate";
                Type= "date";
            }
        ];
     }
}

In the sample, a basic declaration of two classes (Customer and Invoice) has been instantiated using the concept Class defined in the metamodel. Each metamodel concept is instantiated using it as you would be using a class in Java, C# or C++. Properties are assigned in the natural way one would expect in such languages.

As expected, the using operator imports the metamodel to be employed.

In the lines 26-37 you can see how properties can be also defined inline for list contexts.

Under the curtains, the tool is providing code completion, syntax colorization, error management and real-time parsing as you could expect from a modern IDE.

Essential uses DSL text for serialization but also XML can be derived. This XML document is conformant with an XSD derived from the corresponding metamodel.

Intended usage

Consider now, a basic DB metamodel:

namespace Meta.Database
{
    class Schema
    {
		string Name;
		composition List<Table> Tables;
    }
    class Table
    {
		string Name;
		composition List<Column> Columns;
    }
    class Column
    {
		string Name;
		string SqlType;
    }
}

With this base in mind, you can define a business model containing (Customers, Invoices, etc.) based on a class metamodel and then, look for ways to transform your class model in, for example, a DB model representation. This is called, a M2M transformation (Model to Model). Essential will provide specialized languages to do that.

After that, your derived DB model can again be generated to final code, for example SQL DDL scripts in a given certain dialect. This is generally called a M2T transformation (Model to Text) and again Essential provides tools to describe the transformations.

Basically, to complete all this stuff, we need to introduce two more specialized languages: one for applying transformations, and another one for templates to be converted to final text.

I will focus on templates side on the next post.

One comment.

  1. Social comments and analytics for this post…

    This post was mentioned on Twitter by ModelDriven: Modelling with Essential (a new MDD tool under construction) – http://bit.ly/amVNRx – #mdd #tools #dsl…

Post a comment.