Click here to Skip to main content
Click here to Skip to main content

Mo+ - A model oriented programming language and IDE for model oriented development

, 18 Jul 2014
Rate this:
Please Sign up or sign in to vote.
Introducing the Mo+ language and the Mo+ Solution Builder IDE.

Introduction

For effective model oriented development, Mo+ Solution Builder is a tool that uniquely combines a focused and flexible model, a powerful model oriented programming language, and a complete integrated development environment to build and maintain models, and from those models create and maintain code and other documents in many flexible ways.

You can use Mo+ Solution Builder to create and maintain enterprise solutions, software applications, source code in any language, and other materials very quickly using downloaded or created templates written in the Mo+ language.

Mo+ is short for Model Oriented Plus, and is the model oriented programming language that gives users the ability to perform a wide variety of tasks such as creating and maintaining models, documents, and source code in any language. The language has some similarities to object oriented languages such as C# or Java, but has features directly geared towards model driven development.

The free, open source Mo+ Solution Builder is maintained at moplus.codeplex.com. At this site, you can obtain the latest installs, source code, and sample packs containing example code and spec template libraries. There is also a number of video tutorials in the documentation section.

Mo+ Solution Builder uses the following other open source components:

  1. The Mo+ interpreter is powered by the Irony parser (https://irony.codeplex.com/).
  2. Template editing utilizes the AvalonEdit control (http://www.codeproject.com/Articles/42490/Using-AvalonEdit-WPF-Text-Editor).
  3. Document viewing is enhanced with AvalonDock (https://avalondock.codeplex.com/).
  4. Search and replace within template documents is enhanced by this Find/Replace Dialog (http://www.codeproject.com/Articles/173509/A-Universal-WPF-Find-Replace-Dialog).

Why Model Oriented Development (the Mo+ way)?

The goal is to maximize your ability to create and maintain high quality code that meets ongoing requirements and best practices. The Mo+ way is the only one that combines a model driven and truly model oriented approach to code generation. This approach gives you the greatest degree of control over the creation and maintenance of your generated source code and other documents. Ultimately, this means a higher level of quality at a lower cost.

Model Driven

With a model, you have a greater degree of control over template-only code generation approaches. You can more easily wire together different layers in an application, manage exceptions, and identify where business rules and customizations go. With a platform/tier independent model, you can create and maintain code for more layers than you can with other approaches that provide a model tailored for a specific layer and platform.

To make your Mo+ modeling easier, Mo+ gives you complete control in creating and maintaining your model structures and data from other sources such as databases and xml.

Model Oriented

Object oriented programmers know the benefits of object oriented languages over procedural languages in creating large and complex software, benefits such as encapsulation, reusability, modularity, clarity, etc. Why shouldn't you have these same benefits from a code generation perspective? You do with Mo+!

While other code generation template approaches are procedural in nature, Mo+ templates are model oriented. Mo+ templates can be used by other templates just like any other built in property or method. They can be used in expressions, in creating content, and updating output. You can easily divide and conquer complex tasks and specify your conventions and best practices in reusable templates. This high level of reusability of Mo+ templates over other forms of templates will make it easier to maintain and evolve your code to meet ever changing requirements.

In Addition

Most other code generation approaches focus on the initial generation of your code. You have little or no control during ongoing maintenance. With the Mo+ approach, you have full control over creating and updating your code and other documents, as well as removing outdated ones.

To make your work even easier, we plan to continually build upon the set of template libraries (with community input and review) for different models, applications, components, and other documents in various platforms and languages.

Mo+ Notions

Model driven development the Mo+ way to maximize quality and productivity is based on the following notions:

  • You Need a Model - You need a model to represent what you want your system to be and to do. Without the ability to specify the structure and behavior of your system, you are limited in what you can do from a code generation and other automation standpoints.
  • Simple, Focused, Flexible Model – The model structure should be simple, flexible, and focused with only the information needed for model driven development. Design, platform, and tier details should be left out of the model and be handled by processes that utilize the model. Overall, you need the modeling effort to be low.
  • Complete Access to Model – You need the ability to populate your models in any way you see fit. You need the ability to indicate exceptions or other conditions. You may need to create your own model structures. You need the ability to easily recognize your model structures. You need flexible ways to browse, search, and retrieve your model data to perform your tasks.
  • Maximized Code Generation – You need the ability to make the most of your model information, and maximize the quality (not necessarily the quantity) of your auto managed code. Yet overall, you want the code generation effort to be relatively small.
  • Seamless Integration with Custom Code – You need seamless integration of auto managed documents with your custom code. You need the ability to insert and maintain exceptions and specific business rules within generated documents. You need generated and custom documents to coexist gracefully.
  • Complete Control of Code Generation – You can’t afford to have all of your code regenerated every time as part of a team development effort. You need to have full control as to if, when, where, and how to update your generated documents.
  • Best Practices – You want full control over your auto managed documents so that they meet your organization and industry best practices and other requirements.

How Does Mo+ Solution Builder Work?

Mo+ Solution Builder includes some basic features such as:

  • The ability to view and edit models representing your solutions.
  • The ability to load solution model information from database and xml sources (and customize that model data).
  • The ability to create and maintain output solutions, including source code in any language, other models, and other kinds of documents.
  • The ability to create, edit, organize, and debug specification and code templates written in Mo+.

MoPlusUI.png

Using Mo+ Solution Builder, users can create models and output solutions very quickly using libraries of code and spec templates created internally or downloaded. The following diagram outlines the basic process of how this is done.

MoPlusWorkflow.png

In a nutshell, the basic process of using Mo+ Solution Builder to create models and output solutions is:

  • Using the Solution Builder Interface, the user creates a solution model, optionally specifying where model information is going to come from as specification sources. For each specification source, the user chooses a Mo+ template which outlines how to update model information from that source.
  • The Specification Interpreter processes each specification source to evaluate the Specification Input (such as a database or XML file), and update information in the solution model, based on instructions in the corresponding templates. The Specification Interpreter adds information to the model such as features, entities, properties, relationships, and methods, etc.
  • The user can further customize the solution model, adding or modifying features, entities, properties, relationships, methods, etc.
  • The user creates projects in the solution model, which specifies what kind of Solution Output to produce. For each project, the user chooses a Mo+ template which outlines how to create and update Solution Output.
  • The Code Interpreter processes each project to evaluate the Mo+ model, and update Solution Output, based on instructions in the corresponding templates. The Code Interpreter creates and updates information such as source code files, project files, database tables or procedures, test cases, configuration files, and other documents.
  • Using the Solution Builder Interface, the user can also create, edit, and debug Mo+ Specification Templates and Mo+ Code Templates to tailor model updates or solution output updates.
  • The user saves the Mo+ model as a Mo+ Model Doc. This document is simply an XML file that stores only the information that the user creates directly (not information interpreted from specification sources).

Creating And Using A Simple Mo+ Code Template

Here, we will go through a basic example of creating a solution model, a code template, and generating a report. The solution model and template will be presented in its raw format here. The Solution Builder IDE presents this information in a friendly manner with tree views, forms, and text colorization and highlighting, and of course debugging.

It All Starts With A Model

To begin, you need a model to represent the structure and behavior of whatever it is that you want to generate and maintain stuff for. The model contains information such as entities, relationships, properties, and potentially much more.

We will build a simple solution with one feature (Orders), and under that feature we will have two entities (Customer and Order). The Customer and Order entities will have some ID and Name properties.

The solution model is stored as an xml file (such as MyOrders.xml), and our example solution (with other details condensed) appears as such:

<Solution>
    <SolutionName>MyOrders</SolutionName>
    <TemplatePath>
        C:\MyCodeTemplates\EntityAndPropertyReport.mpt
    </TemplatePath>
    <FeatureList>
        <Feature>
            <FeatureName>Orders</FeatureName>
            <EntityList>
                <Entity>
                    <EntityName>Customer</EntityName>
                    <PropertyList>
                        <Property>
                            <PropertyName>CustomerID</PropertyName>
                        </Property>
                        <Property>
                            <PropertyName>CustomerName</PropertyName>
                        </Property>
                    </PropertyList>
                </Entity>
                <Entity>
                    <EntityName>Order</EntityName>
                    <PropertyList>
                        <Property>
                            <PropertyName>OrderID</PropertyName>
                        </Property>
                        <Property>
                            <PropertyName>OrderName</PropertyName>
                        </Property>
                        <Property>
                            <PropertyName>CustomerID</PropertyName>
                        </Property>
                    </PropertyList>
                </Entity>
            </EntityList>
        </Feature>
    </FeatureList>
</Solution>   

Create a Code Template

Here we will create a code template called EntityAndPropertyReport to generate a report for our little solution. This template is stored in a file with the .mpt extension (such as EntityAndPropertyReport.mpt), and appears in its raw format as follows:

<CONFIG>
    NAME EntityAndPropertyReport
    CATEGORY Test
    NODE Solution
    TOPLEVEL True
</CONFIG>
<CONTENT>
<%%-List of entities and their properties:%%>
<%%:
foreach (Entity)
{
    <%%-
    Entity: %%><%%=EntityName%%>
    foreach (Property)
    {
        <%%-
        Property: %%><%%=PropertyName%%>
    }
}
%%>
</CONTENT>
<OUTPUT>
<%%=SolutionDirectory%%><%%-/EntityAndPropertyReport.txt%%>
<%%:
if (File(Path) == null || File(Path) != Text)
{
    update(Path)
}
%%>
</OUTPUT> 

The code template is divided into three sections:

  • Configuration - This is the area bounded by the <CONFIG></CONFIG> tags. This section outlines how the template can be identified and used. This template is identified by its NAME, EntityAndPropertyReport. The NODE is also important, and indicates what kind of instance in the solution model this template operates on to begin with. This is a Solution template, and when this template is called, it will always be passed the solution instance.
  • Content - This is the area bounded by the <CONTENT></CONTENT> tags. This section formulates the textual content that is to be put somewhere and/or utilized by calling templates. This section can contain areas that append raw text to the content, model data and other expression data to the content, and any number of a rich set of statements to perform tasks to build up the content.
  • Output - This is the area bounded by the <OUTPUT></OUTPUT> tags. This section holds the decision making to determine if, when, where, and how to perform updates of the template content and other materials on the file system. This section can contain areas that append raw text to the output path, model data and other expression data to the output path, and any number of a rich set of statements to perform decision making on updating output.

The Content section with proper highlighting, looks like:

Template content section

This section begins with appending some raw text, which is bounded by the <%%- and %%> text tags. Following this is a set of statements bounded by the <%%: and %%> evaluation tags.

Let's look at the foreach (Entity) statement. What's happening here? Being model oriented, when this template is called, it is passed the instance of the solution, which is pushed onto the template's context stack. At the foreach (Entity) statement, the interpreter gets a collection of all of the entities in the solution (which in our case would be Customer and Order), and within the set of statements between the {}s, pushes the next entity in the collection onto the stack (and pops it off the stack at the end of the foreach scope). Within this foreach, you have direct access to an entity's properties, such as EntityName. This is a form of model context, and it negates the need to declare temporary variables to hold the current item within the scope of foreach and other statements.

Within this foreach some additional raw text is appended to the content. Then the entity name, the expression that is bounded by the <%%= %%> property tags, is data that is appended to the content.

The foreach (Property) statement iterates through the set of properties for the entity in the context stack. Within this set of statements, raw text and the property name are appended to the content.

The Output section with proper highlighting, looks like:

Report template output

This section begins with appending some model data and raw text, which is the path of the report file to be updated. The if statement shows some simple decision making on updating the output. Within this if statement are two properties, Text and Path. The Text property holds the content that was formulated in the Content section, while the Path property holds the text that was formulated in this Output section. In this case, the template updates the file at the indicated Path with the Text if the file doesn't exist or if the contents of that file are different than the Text.

Generate Your Report

OK, you have a model and you have a code template, now what? Going back to the solution model file, see that your report template is linked to the solution in the TemplatePath property. This is in effect the main program for the interpreter. You could use the Mo+ Solution Builder IDE to create your report, or you can use the Mo+ Solution Updater command line utility to do it:

MoPlusSolutionUpdater  MyOrders.xml 

Your output report should look something like this:

List of entities and their properties:
    Entity: Customer
        Property: CustomerID
        Property: CustomerName
    Entity: Order
        Property: OrderID
        Property: OrderName
        Property: CustomerID 

In Summary

Once you have your solution model and templates are set up, whether you use the Mo+ Solution Builder IDE or the Mo+ Solution Updater command line utility, the process is the same to update your output solution files (refer to the process diagram above):

  • Your solution file is loaded in memory.
  • If there are any database or xml specification sources to load solution model information (in our example we didn't have any), the specification interpreter calls the main spec template for each source to build up model data. Those spec templates may call other spec templates, etc.
  • The code interpreter calls the solution level template to update output solution files. This spec template may call other templates, etc. (in our example, we didn't have any template calls). If the solution has projects with attached templates, the solution template can call those templates to produce their output (we didn't have any projects in our example).

This very simple example used a single code template. The following image gives a preview of what you can do with templates, calling other templates with or without parameters, and using templates in expressions.

On Viewing the Attached Code

The provided code includes the Mo+ and Mo+ Solution Builder source code (minus third party binaries), sample code templates (with the .mpt extension), and sample spec templates (with the .mps extension).

At the bottom of the list are some sample packs of code and spec templates.

At the top within the Mo+ source, look in the MoPlus.Interpreter, MoPlus.SolutionBuilder.WPFClient, and MoPlus.ViewModel projects/folders. You will find that most of Mo+ Solution Builder is actually generated and maintained by itself (all of the files with _G in the name and a few others). Exceptions are managed either through tagging the solution model (MoPlus.xml), or when necessary adding customizations within protected areas of the generated documents. The templates that are used to generate and maintain Mo+ Solution Builder are also attached (all of this is easier to browse through on the CodePlex site).

A Note on Modeling and Model Structures

If I could make one point on what makes Mo+ different from other approaches, it is that Mo+ gives you the ability to do much more with your models, especially from a code generation perspective. Mo+ tools are currently less focused on the process of modeling from a visual perspective.

Mo+ is not a Modeling Language

Modeling languages such as UML and Mo+ are different beasts altogether. Mo+ is a model oriented language, and is similar to an object oriented language. Mo+ works with model structure elements (like objects) and model element instances (like object instances) to reduce your modeling effort, and to maximize the ability to create and maintain high quality code. Mo+ is designed to create and maintain model structures and data. Mo+ is designed to create and maintain your code and other documents in a model oriented way.

Built in vs. Custom Model Structures

Mo+ the language can work with the built in Entity/Relationship+ structure provided in this version of Mo+ Solution Builder. But, Mo+ doesn't have to work with this structure. In fact, Mo+ can already work with any hierarchical model structure (if you are really interested in this topic, see video tutorial #20 in the documentation section at moplus.codeplex.com). You can create your own model structures to suit your needs. You could even choose to mimic the UML model structure, and write templates to populate and generate code from that model structure. You just wouldn't get the visualization tools.

You ask, why this custom ER+ structure? Well, the idea is to do as little modeling as possible, and pare the model down to essential structural and behavioral details. Developers would make their design decisions less in the model, and more through programming in the templates in a model oriented way.

I'm looking forward to feedback on the language and the built in model structure, to see if more developers want to work with the current or improved built in structure, if more developers want to create their own structures, or if more developers want to work with the UML structure, etc.

Modeling Tools

This version of Mo+ Solution Builder is not intended to be an OOA or OOD modeling tool. The level of modeling Solution Builder provides is more analogous to ORMs such as Entity Framework, but includes behavioral as well as structural elements. Some developers will want to do OOA/OOD modeling, utilizing tools that already exist out there, and some developers will not want to do this type of modeling. Though you can create models from scratch, I'm assuming at this point that most Mo+ Solution Builder users will have model information located elsewhere (in relational databases or xml), do very little additional effort with the Mo+ model, then manage their code from there.

If there are enough users that want to do OOA/OOD or otherwise more extensive modeling with Mo+ tools, I envision that Mo+ tools could evolve to meet that, or be integrated with other tools that provide that functionality. Look forward to more feedback on this topic!

Learn More

There is much more to the Mo+ language and the Mo+ Solution Builder IDE than has been covered here. The language has a rich set of statements to aid in searching, and accessing model data, assembling model data, assembling content, updating output files, and general decision making. Templates can call other templates (with or without parameters) to perform tasks. Templates can be used by other templates just like any built in property or method to easily break down complex tasks. You can define protected areas to save customizations within generated documents.

The easiest way to learn the Mo+ language is to download the Mo+ Solution Builder and sample packs at moplus.codeplex.com. Create solution models and output solutions with these sample packs, and modify or create new templates from there. Mo+ Solution Builder has on board help that provides a detailed how to and reference on the language and model structure as well as the user interface.

Also, to learn more about Mo+ and the Mo+ Solution Builder , there are a number of tutorials in the documentation section of the CodePlex site (moplus.codeplex.com/documentation). The lower numbered tutorials cover simpler topics, while higher numbered ones delve deeper into features and capabilities.

The following articles provide additional information on Mo+:

Become a Member!

The Mo+ community gets additional support, and contributes to the evolution of Mo+ via the web site at https://modelorientedplus.com Being a member gives Mo+ users additional benefits such as additional forum support, member contributed tools, and the ability to vote on and/or contribute to the direction of Mo+. Also, we are running monthly contests for members, where you can win $ for developing solutions using Mo+.

If you are the least bit interested in efficient model oriented software development, please sign up as a member. It's free, and you won't get spam email!

History

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Dave Clemmer
Software Developer Intelligent Coding Solutions, LLC
United States United States
I enjoy coding like an excellent beer. My particular passion and experience lies in the realm of modeling and code generation. In the late 80s and early 90s, I was involved in early modeling and code generation tools that reached the marketplace, including a tool that modeled FORTRAN programs and generated FORTRAN for parallel supercomputer architectures, and a tool that managed Shlaer-Mellor models and generated C++ code. Over the years, I have applied Shlaer-Mellor, UML, and custom modeling and various code generation techniques to greatly benefit the development of enterprise applications.
 
My current passion and endeavor is to foster the evolution of the Mo+ model oriented programming language and related model driven development tools, with as much community input as possible to achieve higher levels in the ability to create and maintain code. The open source site is at moplus.codeplex.com, and the Mo+ membership site is at modelorientedplus.com.
Follow on   Twitter   Google+

Comments and Discussions

 
GeneralMy vote of 5 PinpremiumPrasad Khandekar22-Jul-14 7:34 
GeneralRe: My vote of 5 PinpremiumDave Clemmer22-Jul-14 8:36 
GeneralMy vote of 5 PinpremiumVolynsky Alex23-Apr-14 8:57 
QuestionVery good article! PinprofessionalVolynsky Alex5-Feb-14 9:01 
AnswerRe: Very good article! PinmemberDave Clemmer5-Feb-14 15:01 
GeneralRe: Very good article! PinprofessionalVolynsky Alex5-Feb-14 20:33 
GeneralMessage Automatically Removed PinmemberMember 1056255130-Jan-14 23:40 
QuestionNice! PinprofessionalVolynsky Alex29-Jan-14 10:11 
GeneralGood job! PinmemberAndrea Bruschetta3-Nov-13 4:32 
GeneralRe: Good job! PinmemberDave Clemmer3-Nov-13 10:39 
GeneralMy vote of 5 PinmemberChampion Chen29-Oct-13 15:43 
GeneralRe: My vote of 5 PinmemberDave Clemmer29-Oct-13 16:32 
GeneralGreat Work Pinmembermatrix_resident11-Aug-13 20:22 
GeneralRe: Great Work PinprofessionalDave Clemmer12-Aug-13 3:52 
GeneralMy vote of 5 PinprofessionalPrasad Khandekar28-Jun-13 21:11 
GeneralRe: My vote of 5 PinmemberDave Clemmer30-Jun-13 4:47 
QuestionHow is this better than the ERD editor that already exists for VS? Pinmemberrittjc24-Jun-13 9:43 
AnswerRe: How is this better than the ERD editor that already exists for VS? PinmemberDave Clemmer24-Jun-13 11:18 
QuestionWhy not UML? PinmemberStefan_Lang24-Jun-13 3:45 
AnswerRe: Why not UML? PinmemberDave Clemmer24-Jun-13 7:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 18 Jul 2014
Article Copyright 2013 by Dave Clemmer
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid