Four years ago, having arranged for a new job, I saw a decently sized accounting system in python + wxWidgets + MSSql. All source code was generated automatically based on UML diagrams. A few years later, I was so imbued with this way of development that I began to use code autogeneration in my own Django projects.
Let's take a look at how the process of creating a “code-generated” project looks like?
First we need to find a UML editor with great potential. I am using
Sybase Power Designer . Almost everything is possible in it.
Immediately after installation, PowerDesigner can generate C ++, Java, C #, Visual Basic projects. Writing your code generator is not at all difficult, so we can write and use our own little tricky.
Everything is ready for drawing the first class:

')
Let's call it Foo and add the __call__ method to it:

Let our method print the value of one parameter passed to it:

Now let's see what we will have at the output of the code generator for the created class:

Code generator source code of each class is placed in a separate module. The modules are arranged according to the package hierarchy.
So far, we have not done anything impressive and the code generator has not justified its existence.
Let's extend our example with two more classes CheckHelper, PrintHelper. And let us show that Foo has a connection type of composition with them:

Let's look at the generated code:
# -*- coding: cp1251 -*-
#***********************************************************************
#* Module: foo.py
#* Path: foo
#* Author: danil
#* Modified: 11 2009 . 10:50:37
#***********************************************************************
import checkHelper
import printHelper
class Foo( object ):
class __C_CheckHelper( object ):
def __get__(self, obj, cls):
if obj is None:
return checkHelper.CheckHelper
value = getattr(obj, '#checkHelper' , None)
if value is None:
value = checkHelper.CheckHelper()
setattr(obj, '#checkHelper' , value)
return value
def __set__(self, obj, value):
raise AttributeError
def __delete__(self, obj):
setattr(obj, '#checkHelper' , None)
checkHelper = __C_CheckHelper() #B #B
class __C_PrintHelper( object ):
def __get__(self, obj, cls):
if obj is None:
return printHelper.PrintHelper
value = getattr(obj, '#printHelper' , None)
if value is None:
value = printHelper.PrintHelper()
setattr(obj, '#printHelper' , value)
return value
def __set__(self, obj, value):
raise AttributeError
def __delete__(self, obj):
setattr(obj, '#printHelper' , None)
printHelper = __C_PrintHelper() #B #B
def __call__(self, val):
if self.checkHelper(val):
self.printHelper(val)
* This source code was highlighted with Source Code Highlighter .
It can be seen that the references to the classes are wrapped through the classes. Objects are created once when they are first accessed. The kodogenerator takes on itself the generation of such necessary constructions, the programmer is only required to stretch the arrow with the necessary parameters.
Let's summarize what this approach to project development gives us:
1. Development speed due to automatic generation of generic pieces of code.
2. Ease of reading projects, navigating UML diagrams is much easier than reading source texts in files.
3. Easy to upgrade by quickly tracking all links between objects.
This is only a review article, if the habrosocommunity is interested, I will write step by step tutorials on generating django projects.