Click here to Skip to main content
15,846,078 members

Model-driven development and prototyping by sample

Rate me:
Please Sign up or sign in to vote.
4.78/5 (4 votes)
29 Jul 2013CPOL12 min read 26.6K   172   14   4
When you wonder how boring the repetive work is, think about model driven development.


This introductory article is about model driven development and prototyping in combination to get solutions very fast. It is related to database applications or business applications in general where the topic is applicable at best. For the sample demonstrated here and the applications used, you need a Windows operating system, but this is not required in general if you use another template that targets GTK+ for sample.


Writing software is usually a time consuming job. Some of the time consuming tasks are luckily reduced to some mouse clicks by intelligent IDE's but not all is reduced what can be done with much less time. XSLT and therefore code generation or model transformation is the technique used behind the scenes. At the end two applications are used to reach much more automation - an UML editor and an application prototyper that is capable to understand some specific UML models to enable running these models as prototypes and at the end also to output code - again with XSLT transformations.

Required tools  

Here I will shortly describe tools that are required to follow this article. First you need the application to model your UML diagrams. Second you will need the application that represents the UML model as an applicatin prototype  and as third, you need a template that is used in this article. The template is responsible for generating code. The last is a commercial framework, the generated code is using. It is the very good DevExpress framework and an evaluation version can be downloaded as well.

The first application is ArgoUML and probably well known. You could download this software from here. When you have downloaded and installed the application you may do the same for the second application as well. It is the main application within my open source project DMF: Distributed Multiplatform Framework.  The third piece of software is the template that is also part of my open source project and available here. And last but not least you require the DevExpress framework to be able to compile the generated code. To not forget it, you of course need Visual Studio or SharpDevelop.  To compile and run the application in this article, you also need a SQLite .NET assembly. You could get this from here. Choose the correct one for your system (eg. 32Bit or 64Bit).

Find the repeating points in your project

Before we begin with a model using UML and creating a prototype, it is important to understand why we use these tools. Some of you have learned to use UML for documentation only, others have learned to use it as first class members of development artifacts. I am in the second group.

To the point: The repeating points in your project are database forms for sample, or the entity classes that are used in these forms. These parts are automatically created from powerful IDE's.  


These parts are ideal candidates for automation. The relevant information comes from the database schema and thus could be reduced to this information.

Next, you will complain about these generated forms to be not well suited for your needs. This is true.

But why? 

You do not have the control over the generated layout without picking each column in a table and select the control of your choice, or setup these settings in the IDE. The datasoure base settings are per column:

Image 1

In my point of view, this is not good as you have to choose this before creating a form by drag&drop. It is therefore not good as you make these changes individually per form and not per project requirements and thus you may make different choices by mistakes.  For sample, you forget the phone number formatting in one form, but have done so in another form.

Is there a solution to this? 

You could choose to setup this in the IDE. Here is the settings: 

Image 2

But this is still not the best solution to the problem. You could not setup these settings per project. You may export and import the IDE settings and probably do this automatically, but this is IDE related and not meta data related as your choices are.  Also it is tool related and this is information you probably loose when you ever should change the IDE.

The best solution in my point of view, is to put the information about what kind of control to be used to the type of the column - indirectly. To do this, you could create custom database column types that are then used, or you could move the complete model information out of the target database. 

Moving to a modeling approach

The last part showed up some issues when using tools directly and put too much information into the project by picking control types per table row or per project settings in the IDE. A main point here are the following questions:

  • What do you when you like to change a control type for all your telephone numbers in your application forms?
  • Do you go to each form and fiddle the type used? 
  • How do you know where all the phone numbers are used?

Here is the point you should start thinking about modeling and using meta information. Not that you can speed up the creation of ALL forms and entity classes by code generation (as the IDE does this only partly), you could repeat this every times - if you separate handwritten code from generated in your architecture design. 

If you control the creation of the forms and other source artifacts, you can control the used controls via a mapping from your domain types (namely not using a text field for the telephone number type, but rather phonenumber type it self). Doing so, you define the target control type by the mapping from the used type and thus each usage of this type reflects to a consistent look and feel.

Start modeling

To show some real, I start modeling a small address book application for you. Here is the resulting application that has been generated 100% including the complete project files: 

Image 3

The application should store your contacts in a database. A candidate for modeling this in UML and using code-generation - a typical database related type of application.  Note the subgrids for each contact. A contact may have multiple phone numbers and also more than one address.

If you have downloaded ArgoUML and started it, please follow these steps for a valid model.  First, you need a name for the model. Name it AddressBook.

Image 4

After changing the project name and the package inside, you will have the following model:

Image 5

The package name is later used as the application name - it may later required to have multiple packages, but this is another issue for much bigger models and projects.

Now when you have done the first settings, add some basic types to the model. Here you see some basic types that are supported out of the box by the later steps.

Image 6

To become concrete, add a type phonenumber, you will use in the upcoming article, The phone number will demonstrate the change and the solution to the mentioned problems. Then you need to create some classes for your new application. Add Contact, Address and Telephone with the including attributes with given types. (Keep using string for the Number attribute in the Telephone class)

Image 7

To get the final model, you need to add a new stereotype to be used in the aggregates. The stereotype used, defines a requirement for the application. To enable the subgrids in the application and thus to open the details, you must specify this anyhow. This is due to not do this for each aggregate in the model but only for that class relations (aggregate) you like.  To create the stereotype, right click on the AddressBook in the picture and add a new model element (stereotype):

 Image 8

Name the stereotype masterdetail_action and check if the base class (Basisklasse is Association. Then choose this for the aggregates in the stereotype properties. If you do not see the new stereotype, the base class was not set. (Note: The base class must be empty when the model gets exported - but later more about this).

You now have a model that looks like this here:

Image 9

The relation (aggregates) have names. The meaning for this is the following: If there is shown a foreign key value in a form or grid, it should be used a dropdown box instead and the display name is the name in the brackets of the association.

Now the model has been completely created and you are ready to get it into an application. Therefore you have downloaded the binary samples installer from the required application section. You will find an icon on the desktop after installing like this:

Image 10

It starts up the application prototyper in that you get the model imported. But first you need to export the UML model as an XMI file (in the file menu).

Note: Before you export the XMI file, please remove the base class from the stereotype. If not, this will currently break the import and further steps. You only need the base class, to be able to select the stereo type in the properties while modeling. (I will create a workaround in the XSLT templates when I have time)

Image 11

If you have this done, start the application prototyper that I still have named lbDMF, but the application behind is wxWrapper. This is due to the fact that the application you will start is indeed itself also a prototype!

When you start import the XMI file, please note that you get a red colored property field. This is due to changing the XMI input file to not forget naming the initial database name like the project name or better the application name:

Image 12

Also note, for this document I have not overwritten my last XMI file for safety reasons. I have named the file AddressBook1.xmi. This does not matter. Change the database name exactly to the one you have chosen for the package - e.g., AddressBook. Then import the XMI file from the file menu:

Image 13

Then you will get a safety dialog that you have to click with no, if all is OK:

Image 14

If you not have checked a menu entry to write XMI settings. This is more or less obsolete, because the settings are passed by XSLT parameters into the generation process.


Image 15

This is because you may have not chosen to override the application database when you repeat the import a second time and choose to create the database schema for the modeled application. This has an effect in the SQL scripts that are generated and will include drop table statements. Be sure you have no data to loose! 

In this case, the application database will be created the first time and does not drop any tables, else you will be prompted with a message like this:

Image 16

The next two dialogs will ask you to do so for the application database and for the model database. Both can be answered with yes the first time. The first question let you skip the creation of the application database and the second let you skip the import into the systam database (that contains the model of the application).

When you have finished the importing step, you could reload the application from the menu. First you will not see the AddressBook application but after a first reload of lbDMF Manager which is running.

Image 17

At that point, you could open the imported application and try enter some data. This is the prototype step of the application. It is possible to import an application model (XMI) like this one and then directly run the application. The prototype is any point before you make a decision about the target application you then create by code generation.

Note: You are using a prototype that comes from a XMI model (using BoUML and XMI 2.1).

But I'll skip that and go further to the generated application. Therefore you need to download the CAB DevExpress compilation setup and install it where it suggests to (C:\lbDMF) even it complains about the folder. When that is done, you are ready to create the application I have shown at the beginning:

Image 18

Click 'Next' until you find AddressBook in the name field. Then press the button 'Codegenerieren' and choose a target folder (C:\lbDMF) in the case for the template you like to use for this article.

Image 19

Then click to Ja:

Image 20

And choose the template from the CAB DevExpress compilation folder:

Image 21

If all goes well, you will get an application created that only needs a Sqlite .NET assembly to enable compiling and running the application.

Using the code    

The following download contains all required stuff you need - e.g., the UML model. To repeat the modeling may introduce errors. Thus I'll include the XMI files (original and that of this writing) to ensure your success. Also the zargo files are included. The tools that are required to repeat the modeling, are not included here, because they are reachable from it's origin and linked in the required tools section above.

If you have any problems to follow, or any issues about the article to improve, please let me know this by contacting me. 

Points of Interest 

The next article will contain customizing the model and creating a phone number control to replace the first versions text field with a formatted text for phone numbers. The issues for that were noted above and are very important in my point of view. But this is beyond simple modeling and includes modification of the XSLT templates including code fragments to generate the new formatted text box for phone numbers.

Also I like general feedback. I have at least created a statistics page for a little feedback as possible by opening that page, if you follow the product anouncement at CodeProject from here.


This is the initial release.


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

Written By
Software Developer (Senior)
Germany Germany
I am a software developer with passion to MDSD.
Starting with the good old 'Brotkasten' I learned programming.
You will find more at

Comments and Discussions

Questiongood job overall Pin
Emmet M26-Jan-15 9:35
Emmet M26-Jan-15 9:35 
AnswerRe: good job overall Pin
Lothar Behrens27-Jan-15 20:51
professionalLothar Behrens27-Jan-15 20:51 
QuestionThanks Pin
Mohsen Solhnia20-Oct-13 10:51
Mohsen Solhnia20-Oct-13 10:51 
QuestionPerhaps a different title? Pin
OriginalGriff28-Jul-13 3:53
mveOriginalGriff28-Jul-13 3:53 

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

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