Overview of Code Generation

Chapter 4 - Generating Code From the Visio Model
byAndrew Filevet al.?
Wrox Press ©2002
Team FLY

Code generation is an automated process of obtaining programming-language source code from a UML model.

Once you have properly described the static structure of your system, Visio can generate code skeletons from your models in one of three languages - C#, Visual Basic .NET, or C++. The current version of Visio works only with the static model of the system and does not support generating method stubs from activity or sequence diagrams.

Visio can generate the code for the classes and packages you specify from the whole static model, not only from the entities that reside on static diagrams, and can either generate the code into files, or place the generated code into a Visual Studio .NET project.

Furthermore, for each level of the model - class, attribute, or operation, Visio allows the developer a preview of the code that will be generated, and also to specify the language, code template, and the documentation produced.

With code templates, the developer is able to specify the structure of the source code generated by Visio. Code templates can be modified and customized, meaning that in-house coding styles can be enforced, resulting in standardized source code, and also extending the flat code generations options of the UML. We'll see more about this later in the chapter.

The completeness and correctness of generated code depends on the accuracy with which you have developed your model - an ill-defined model may not result in correct code generation. For example, you have the power to define the body of operations in Visio, so you have the power to do a 100% complete model in most cases.

It is worth remembering that although Visio allows you to enter code for the body of operations, when you write the body of, say, a method in a particular programming language, you make the model dependent on the programming language. Suppose you have created a 100% complete C# model, generate C# code from it, compile, run, and have fun. Now try to generate Visual Basic .NET code from it - all the code in the body of your methods, which you have carefully written yourself in C# will not compile in VB.NET of course.

Another important point to keep in mind with code generation is that UML is a modeling language and C++, Visual Basic .NET, and C# are programming languages, and each of them has its own flavor of syntax and structure. Thus you should be ready to sometimes modify the model in order to generate code into your favorite language.

Team FLY


Professional UML with Visual Studio. NET. Unmasking Visio for Enterprise Architects
Professional UML with Visual Studio. NET. Unmasking Visio for Enterprise Architects
ISBN: 1440490856
EAN: N/A
Year: 2001
Pages: 85

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net