Roper application design is a must in any project. without this step, it is almost guaranteed that problems will occur. this is especially true in the component world. this month I am going to take a look at Microsoft Visio 2000 Enterprise Edition to see how it can be used to enhance the application design process. Visio is a well-known drawing tool for creating ad-hoc drawings, floor plans, network diagrams, and almost any other type of dimo-you need. this strong graphical heritage makes Visio a good choice for Drawing Software Engineering diagrams. the keys to software engineering are supplying the proper drawing tools and providing integration with the coding environment or language. i'll take a look at both of these issues. Visio includes a number of different dimo-types that can be used to create Software Diagrams. Figure 1 provides a brief listing of the available options. The variety of chart types make Visio a great candidate for projects that require has different types of charts. Visio can also generate database diagrams and schemas, further adding to the utility of this tool. After carefully reviewing the Visio documentation, I found that the only model that seems to be able to generate code is the UML model. you can generate code from any UML model that contains class definitions for C ++, the Java language, or Visual Basic. You can use the UML solution to reverse-engineer a project's class definitions, and then generate UML static structure models. this works only for Visual C ++ 6.0, Visual J ++ 6.0, or Visual Basic 6.0. to facilitate the integration between Visio and Visual Studio, Visio installa custom toolbar for Visual Studio if it's on your system when you install Visio. Let's take a quick look at how Visio can be used with Visual Basic in the software design environment. Starting a software project The first step you must take in your application design process is to start Visio and select the UML model, as shown in figure 2. once you have selected the model, click OK. this will open Visio with a new model and the UML tools displayed. the UML navigator Explorer window can be found on the left side of the drawing (by default) and the drawing Panel (including the UML stenric) will consume most of the window, as shown in figure 3.
|
Figure 2 selecting dimo-type |
The UML navigator shows a tree view of your Visio project. you can interact with the UML navigator to create new elements or change existing ones. anything you do with a model's elements shows up in the UML navigator, whether you modify it there or in a drawing. when you create a new model, the UML navigator shows the default items, as shown in figure 3. Now that you have a model open, how can you design an application with it? First, think about what you are going to build. for this application, let's create visual basic-based components that handle the business logic. before you start designing your model for the components, you shoshould take care of a few settings. First, you shoshould Select Code | preferences from the UML menu. this will display the code generation preferences Dialog (see figure 4 ). this dialog allows you to set a number of settings ranging from the directory that is used for generating code files to the actual settings for those files.
|
Figure 4 setting initializers and finalizers |
Select Visual Basic as the language to use. next, select the folder for Visio to generate code into by entering the folder name in the project directory textbox. note that you can also use the Browse button to select the folder. the folder must exist before you select it, but you can create a new folder with the context menu. Using this dialog You can also change a number of settings that affect your generated code. the Tree of options has two major folders. the global Default preferences folder contains all of the global preferences. the element pre-ferences folder contains specific settings for the project. as you add classes to a Visio project, they will become visible under the element preferences folder and you can explain icitly choose special settings for them. For instance, you can select the initializers and finalizers under the Global Default preferences folder and then turn on and off the creation of the initialize and terminate events in each class, as shown in figure 4. At this point, the your project is set to use Visual Basic as its language. now you can begin to work with the digoal. in the template, click the UML static structure header in the stenpencil to display the UML shapes for classes and key shapes you will need. The first step you usually take in building components is to lay out the classes for a component and the interface (methods and properties) for each class. the UML representation for a class is the class shape. you can add a class by dragging it from the UML static structure and dropping it on a digoal. the class then represents your class and will be used by visio to generate the class module. the sample model shown in Figure 5 has two classes: customer and customerdbservice. Figure 5 shows the classes and their interface. to create each class, I dropped a class shape from the stenric into the digoal. then I double-clicked the shape to set its properties. the Name property sets the class name (logically enough ). make sure the visibility list shown at the bottom of the Code Generation preferences dialog is set to public in order to make the class available to the applications and objects that will use it. The Operations tab of the class Properties dialog is used to create and set the names of the methods belonging to the class. to enter a method, click the new button, then double-click in the operation field to set the default name and change it to the proper method name. then select the return type for the method and select the visibility setting to control the visibility of the method. figure 6 shows the settings for the methods in the customer class.
At this point, the methods do not have any arguments. to add arguments to a method, select the method in the operation list, then click the Properties button. the Operation Properties dialog will be displayed next (see figure 7 ). if you set a return datatype for the method, the method's name will appear in the list with the kind column set to return. to add a parameter for the method, click New, then enter the name for the parameter and select its datatype. figure 7 shows the dialog with the parameters for the retrievetitle method. after adding all of the properties, click OK to close the dialog. when you have added parameters for all of your methods, click OK to close the class Properties dialog. now your class dimo-shocould show the class complete with its methods, parameters, and properties, as shown in Figure 5.
|
Figure 7 method parameters |
Now you can adorn the class with other features. for instance, you can draw links, add notes, or add any other information to the model by adding the shapes to the drawing and annotating them. the link between customer and customerdbservice in Figure 5 is a generalization link. the properties for the link have the stereotype set to uses (indicated by the word uses on the link in Figure 5 ). certain shape properties such as link also control how the code is generated. if you do not set the Link Properties to uses, the generated code from Figure 5 will actually contain an implements statement and implement the interface of customerdbservice in customer. changing the stereotype property to uses changes the generated code layout. Another item you shoshould notice is the folders in the UML navigator. as Figure 5 shows, when you define an item using a shape in the model, it automatically shows up in the UML navigator. underneath the static model folder is the package folder. in Figure 5, this folder is named customerpackage, which is the name that I entered for it. underneath the customerpackage is the customerstructure, which contains the shapes for my classes. you can see the classes listed underneath the customerstructure. the package and structure folders are containers that you can use to organize your model. the package folder is important because its name is the name of the folder that Visio will use to place the class files it generates when you generate yours. visio will automatically create the package folder underneath the path that you have entered in the preferences. Now for the fun part. once you have created your model and fine-tuned the classes, you can have Visio generate the classes for you. to generate the code, select code from the UML menu, then select generate. this will display the Code Generation Options dialog shown in figure 8. you can select each of the classes you want to generate, or you can select all of the classes in a container by clicking the box next to the container containing the classes you want to create. figure 8 shows the settings after I selected the customerpackage entry. in this dialog You can also change the path for the generated code and the path the code will be generated. to actually generate the code, click OK and Visio will create the code files.
|
Figure 8 Code Generation Options |
When you are designing a class in Visual Basic, you must first consider the component it is tied. you can tie your UML classes in Visio to a component shape in the divisor. when Visio generates the code for the classes, it does not use the component information with your generated code to create a visual basic project. instead it simply adds the class files to the package directory under the path you entered. once you have generated the class files, you must add them to your visual basic project from the Visual Basic Editor. You can also preview the code for a class without saving it to disk. to do so, select code from the UML menu, and then click preferences. expand the element preferences folder, then select the class you want to preview. now click the preview button to display the code in the preview editor. here, you can copy the code to the clipboard and then paste it into a module or other editor. Conclusion Visio is quite a powerful program. one of its own strengths is its ability to produce a wide number of drawings and diagrams. the specified Software Diagrams that are available make it a good choice for producing software architecture diagrams. The main drawback in Using Visio instead of a specific software modeler is that Visio is still a general-purpose drawing tool that can also produce software diagrams. specific modeling tools are designed to produce only Software Diagrams or possible software and database diagrams, and are therefore richer in those areas. Using Visio to dimo-component classes is a far cry from web development, right? Not really. today it is vitally important for every development project to contain some type of layout process. this allows members of the Web team to understand the overall architecture and flow of the site and make fundamental decisions about where the reusable code is, what the common services are, how data access is achieved, and so forth. without this design step you are flying by the seat of your pants, so to speak. |