Note: The latest source code can be found on github at github.com/moplus/modelorientedplus. The installers (including support for visual studio packages) and sample packs for the latest release are located at github.com/moplus/modelorientedplus/releases.
Mo+ is also available as an extension in the Visual Studio Gallery.
What is Model Oriented Development?
Model Oriented Development (MOD) is a process that allows you to utilize a simple, focused model for development purposes at any point in the development process. You translate model information into source code and/or documents using model oriented patterns or templates.
Why Consider Model Oriented Development?
You are a busy software developer. You work on legacy systems or you create new systems from ground zero. You are a proponent of or must conform to processes such as waterfall, scrum, or test driven development. You like or must work in specific programming languages. You have time and other constraints in your daily work. Why would you consider adding something such as model oriented development?
Model Oriented Development (MOD) benefits your development work by being:
-
Flexible - With MOD, you don't have to change your current overall development process at all. You can choose to utilize a simple, focused model early or late in your development process. You choose how little or how much to leverage your models to generate and maintain code in the languages of your choosing. You seamlessly integrate your generated code with your custom code.
-
Productive - Scale and leverage the work you already do. Instead of writing similar things many times, write a model oriented pattern for a component once, and apply that for all similar things in your work.
-
Powerful and Robust - Plain old template/procedural based code generation tools too often fall flat when you need them to solve complex problems with business rules and exceptions. Well-written MOD tools, like Mo+, give you full access to your models with the ability to indicate your rules and exceptions. Model oriented patterns give you the power to solve very complex problems! Your bug count tends to be lower in model oriented code since issues are usually encountered and resolved early.
-
Reusable - Reuse your model oriented patterns written to your best practices not only on your current project, but for future projects as well! Reuse powerful team or community developed and reviewed patterns.
In short, model oriented development allows you to continue to do the work you already do, and it allows you to scale your work to do it better!
Requirements for Effective Model Oriented Development
For effective model oriented development, the following requirements are essential:
-
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 code generation and other automation standpoints.
-
Simple, Focused, Flexible Model – The model structure should be simple, flexible, and focused with essential information needed for model oriented development. Design, platform, and tier details often should be left out of the model and be handled when you translate your model information into code and documents. 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 and documents. Yet overall, you want the code generation effort to be relatively small.
-
Seamless Integration with Custom Code – You need seamless integration of auto managed code and documents with your custom information. You need the ability to insert and maintain exceptions and specific business rules within generated documents. You need generated and custom code and 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 code and documents.
-
Best Practices – You want full control over your auto managed code and documents so that they meet your organization and industry best practices and other requirements.
Introducing Mo+
There are three approaches that are proven to be effective for many software development applications: modeling, template based code generation, and object oriented programming. Mo+ is the first technology to merge these approaches, and evolve them into a truly model oriented approach for effective model oriented development.
Mo+ uniquely combines focused and flexible models, 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:
-
The Mo+ interpreter is powered by the Irony parser (https://irony.codeplex.com/).
-
Template editing utilizes the AvalonEdit control (http://www.codeproject.com/Articles/42490/Using-AvalonEdit-WPF-Text-Editor).
-
Document viewing is enhanced with AvalonDock (https://avalondock.codeplex.com/).
-
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 Use Mo+ for Model Oriented Development?
In short, Mo+ is the only technology the "completes the loop" in unlocking the full power of model oriented development, allowing you to do things in a model oriented way that you simply cannot with other technologies. Mo+ satisfies all of the above stated requirements with ease.
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 when managing templates for model oriented development? You do with Mo+!
While other code generation template approaches are procedural in nature, Mo+ templates (and the language) are model oriented by design. 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.
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.
How Does Mo+ Solution Builder Work?
Mo+ Solution Builder includes some basic features such as:
-
The ability to view and edit models representing what you want to develop.
-
The ability to load model information from database and xml sources in any way you want to, and give you the means to customize that model data.
-
The ability to create, maintain, and integrate your model oriented work with your overall work, 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+.
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.
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:
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:
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.
Using the Attached Downloads
The attached downloads give you several options for installing and using Mo+.
You have a couple of options to install Mo+:
- Installer - WinApp + VS2010 + VS2012 + VS2013 - Use this intall if you use Visual Studio (2010-2013). The non visual studio windows application is also provided, and there is no harm installing this even if you don't have Visual Studio.
- Installer - WinApp Only - Use this lighter weight install if you don't plan on using Mo+ with Visual Studio.
You have a some sample packs to help get you started in creating solutions with Mo+ (you can use any of these sample packs as starting points to create models and solutions exactly as you want to):
- Getting Started Pack (templates) - This sample pack shows you some simple template examples to give you an idea on how to use Mo+. See the readme in that download for more details.
- Models and .Net Sample Pack (templates) - This sample pack gives you the ability to load information from MySQL and SQL Server databases (spec templates) and the ability to generate a variety of .net solutions (code templates). See the readme in the download for more details.
- Entity Framework Code First Sample Pack (templates) - This sample pack gives you the ability to generate a working multi-tier application utilizing Entity Framework code first. See the readme in that download for more details.
See the readme and source code downloads for additional information.
On Viewing the Attached Code
The source code is available at moplus.codeplex.com, where you can download the latest source as well as installers.
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!
Key Benefits
What can Mo+ do for you? Following are some key benefits:
- Scale your work - Instead of doing a similar piece of work 100 times, do it once with Mo+ and let Mo+ manage those 100 pieces of work for you!
- Reuse your work - Make model oriented building blocks that represent conventions and other rules once with Mo+. Reuse those building blocks many times to generate all kinds of components in your system. You can often reuse these same building blocks and higher level templates to build different systems with different models!
- Increase your ability to make changes - When more of your system can be managed in a model oriented way, you can easily change both the model and how the way model oriented components are built and let Mo+ update those components automatically. Then, all you have to do is change your custom code. If you have model oriented tests managed by Mo+, testing those changes becomes that much easier.
- Codify your best practices - Codify your best practices as model oriented building blocks, making your overall code (even custom code) more readable and consistent.
- Let you focus on your ideas - With all of the above benefits that greatly help manage the mundane and repetitive tasks, you have much more time to focus on your ideas!
Key Uses
When would you use Mo+? Following are some key uses (use cases):
- When building a system from scratch - Build a system from scratch, using Mo+ to scale your work as you develop or use templates, and as you build up your model.
- When improving a legacy system - Create a model or import one from an existing source such as a database. Rework components in a model oriented way as you need to make feature changes and other improvements. Start with model oriented tests first for immediate benefit!
- When building multiple systems - Reuse the templates you created or used for one system, and build other systems with different models. Your best practices and technical approaches implemented in a model oriented way make creating new systems that much easier!
- When rapid prototyping - Use a Mo+ sample pack to generate working applications right away with your model! Rework your model as you iron out requirements, then change templates or make your own to support the code you really need.
- When migrating a system to new technologies and approaches - Embody your technical changes as model oriented templates, allowing you to make these changes much faster.
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