UML Modeling on NetBeans, Part 3: Generate code from UML Diagram

This entry is part 3 of 4 in the series UML Modeling on NetBeans 5.5

UML Modeling on NetBeans, Part 3: Generate code from UML Diagram

In this part, I am going to show how to generate code from existing diagram so that it can reduce a lot of work if you have an well-defined diagram. Also, it can make sure that the coding structure of your project will conform as in a diagram.

  1. Suppose I have an existing class DicomImage in Model1 Project as in figure below.
    Class diagram example
    DicomImage class
  2. Before we start, let choose where to save source code file. Let say, I want to put source code in Source Packages, Dicom project. (“C:\Documents and Settings\Linglom\Dicom\src”)
    Destination to generate code
  3. Now, let generate code. Right click on Model1 Project, select Generate Code…
    select generate code on pop-up menu
  4. Select destination to put the source code, I use location from 2. Click OK.
    If you don’t want to backup file, just uncheck the box.
    select destination
  5. If you have just created a diagram, it will ask to save it first. Click OK.
    Confirm save
  6. When code are generating, you will see the progress in the output window.New file was created
  7. When it finished, you will see the new file in destination Project was created. Try open it and you will see some source code that it has generated for you.
    Generate code finished
    Created source code

This tool is useful if you have a clearly well-defined diagram. But keep in mind that if your diagram contain some errors, your generated code may effected from that, too.

Series Navigation<< UML Modeling on NetBeans, Part 2: Create a Use Case DiagramUML Modeling on NetBeans, Part 4: Generate UML Diagram from Code >>

3 Comments

  1. Saul February 16, 2007
  2. linglom February 16, 2007
  3. Ad June 23, 2007
  4. Pingback: Florecista’s Weblog September 10, 2007

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.