Artifacts > Analysis & Design Artifact Set > Design Model... > Design Class > Guidelines > Designing Classes in Visual Basic

This is an outline of class design guidelines applicable to a Visual Basic® project using Rational Rose® as a modeling tool; these guidelines might be further refined to fit into a specific project environment.

These guidelines are structured according to the Activity: Class Design, presenting specific guidelines for each step within that activity.

Topics

References To top of page

The following books and documents are referred from these guidelines:

  • Visual Basic® Books Online, Enterprise Edition, version 5.0.
  • Rational Rose® add-in help documentation, Enterprise/Professional Visual Basic® Edition for Windows 95/NT 4.0.

Terminology To top of page

The Rational Unified Process (RUP) description is based on UML terminology, meaning that it in some cases need to be mapped onto corresponding Visual Basic® and COM terminology. There also exists an option in Rational Rose® that can be set to view the model using COM terminology; when doing this, the following terms are changed:

RUP/UML

Visual Basic®/COM

operation method
parameter argument
attribute property

This must be kept in mind when interpreting RUP descriptions.

Mapping the Design Model to Visual Basic Code To top of page

Refer to the Rational Rose® add-in help file, "Rose Visual Basic," section "Reference," subsection "Model to Visual Basic Mapping."

Creating Initial Design Classes To top of page

Initial Boundary Class Designs

A boundary class representing a part of the user interface is likely to start out as a form.

A boundary class representing interaction with external systems represents in most cases a reference to an ActiveX component or a DLL. This is done by declaring an object variable or a DLL procedure, respectively, and then use this variable or procedure to access functionality. We recommend that this object variable or procedure declaration is done within the same module, and that the usage of the variable or procedure is encapsulated within the module. This will localize changes to the external interaction.

Initial Entity Class Designs

An entity class is likely to start out as a class marked as persistent. When this "data class" has been refined, DDL scripts defining the corresponding database tables can be generated (see "How to Handle Persistency" below).

Initial Control Class Designs

A control class is likely to start out as a class module.

Defining Operations To top of page

Define Visual Basic methods in terms of sub, function and property procedures.

Refer to the Rational Rose® add-in help file, "Rose Visual Basic," section "Reference," subsection "Model to Visual Basic Mapping," subsubsection "Method Mappings," for details.

For method naming guidelines, refer to "Visual Basic® Programmer's Guide," part 2: "What Can You Do With Visual Basic?," section "Programming with Objects," subsection "Naming Properties, Methods, and Events."

Defining Attributes and Relationships To top of page

Designing Attributes

Note: "Designing attributes" means "defining class properties" in a Visual Basic® context.

From Rational Rose, class properties are translated into data members. By default, Rational Rose® does not generate the property Get, Set and Let procedures corresponding to each property. A model property allows the user to turn on automatic generation of property procedures.

Refer to the Rational Rose® add-in help file, "Rose Visual Basic," section "Reference," subsection "Model to Visual Basic Mapping," subsubsection "Properties," for details.

For property naming guidelines, refer to "Visual Basic® Programmer's Guide," part 2: "What Can You Do With Visual Basic?," section "Programming with Objects," subsection "Naming Properties, Methods, and Events."

Designing Associations

Associations map to pairs of data members in Visual Basic®. The name for each data member is taken from its association role name.

You can use associations (and aggregations, see below) to model so called "object models" in Visual Basic®; refer to "Visual Basic® Programmer's Guide," part 2: "What Can You Do With Visual Basic?," section "Programming with Objects," subsection "Object Models."

In Rational Rose, associations can be described in detail by assigning a variety of adornments and properties. These adornments include association direction, roles, multiplicity, navigability, aggregate, access, containment, role documentation and constraints, association classes, and qualifiers.

Refer to the Rational Rose® add-in help file, "Rose Visual Basic," section "Reference," subsection "Model to Visual Basic Mapping," subsubsection "Relationships," subsubsubsections "Association Relationship and Advanced Relationship Mappings," for details.

Designing Aggregations

An aggregate relationship is conceptually the same as an association with the aggregate adornment set. Aggregate adornments have no effect on code generation, nor reverse engineering, in Rose. Also, the aggregate association is navigable on both ends, and data members are generated for each of the associated classes.

Depending on the type of aggregation, you should clarify the design as follows:

  • Define shared aggregates by setting the "By-Reference" containment adornment.
  • Define composite aggregates by setting the "By-Value" containment adornment.

Refer to the Rational Rose® add-in help file, "Rose Visual Basic," section "Reference," subsection "Model to Visual Basic Mapping," subsubsection "Relationships," subsubsubsections "Aggregation Relationship and Advanced Relationship Mappings," for details.

Designing Generalizations

In Visual Basic®, the closest correspondence to the generalization relationship is the implements construct. Thus, for a generalization relationship between a subclass B and a superclass A, Rational Rose® generates the following code into B's class module:

· An Implements A statement

· An object of the superclass

· Copies of A's public methods, including default dispatching implementations that delegate to the parent class A

Refer to the Rational Rose® add-in help file, "Rose Visual Basic," section "Reference," subsection "Model to Visual Basic Mapping," subsubsection "Generalization Relationship," for details.

Regarding the implements construct, refer to "Visual Basic® Programmer's Guide," part 2: "What Can You Do With Visual Basic?," section "Programming with Objects," subsection "Polymorphism."

Designing Subscribes-Relationships

Declare, raise, and handle the corresponding events.

Refer to the Rational Rose® add-in help file, "Rose Visual Basic," section "Reference," subsection "Model to Visual Basic Mapping," subsubsection "Events," for details.

For event naming guidelines, refer to "Visual Basic® Programmer's Guide," part 2: "What Can You Do With Visual Basic?," section "Programming with Objects," subsection "Naming Properties, Methods, and Events."

Defining (UML) Methods To top of page

Methods (UML) can be specified on the Semantics tab of the (VB) method specification in Rational Rose. The (UML) method pseudo-or implementation code will be code-generated as a comment within the corresponding method in Visual Basic®. This comment can then be used as a starting point for the (VB) method implementation by removing the "comment ticks."

Defining States To top of page

Rational Rose® does not support code generation from state machines. However, you should still define state machines in Rational Rose® if the objects of a class exhibit interesting state-controlled behavior; this will provide valuable information to the implementer of the class.

Handling Non-Functional Requirements in General To top of page

How to Create the User Interface

Refer to "Visual Basic® Programmer's Guide," part 2: "What Can You Do With Visual Basic?," sections "Creating a User Interface and Using Visual Basic's Standard Controls."

Also refer to Guidelines: User Interface (General), for more information on how to create user interfaces.

How to Reuse ActiveX Components

Refer to "Visual Basic® Programmer's Guide," part 2: "What Can You Do With Visual Basic?," section "Programming with Components."

Also refer to the Rational Rose® add-in help file, "Rose Visual Basic," section "How to…," subsection "Add Existing Software Components to a Model," for details.

How to Detect, Handle and Report Errors

Refer to "Visual Basic® Programmer's Guide," part 2: "What Can You Do With Visual Basic?," section "Debugging Your Code and Handling Errors."

Also refer to the Rational Rose® add-in help file, "Rose Visual Basic," section "How to…," subsection "Generate Visual Basic Code," subsubsection "Generating Error Handling Code."

How to Handle Persistency

Refer to "Visual Basic® Programmer's Guide," part 2: "What Can You Do With Visual Basic?," section "Accessing Data."

If you are using the professional and enterprise edition of Visual Basic, also refer to the "Guide to Data Access Objects."

Also refer to Activity: Database Design, for more information on persistency issues.

Also refer to the Rational Rose® add-in help file, "Rational Rose," section "Concepts," subsection "DDL Code Generation," on how to generate DDL code.

How to Design for Performance and Compatibility

Refer to "Visual Basic® Programmer's Guide," part 2: "What Can You Do With Visual Basic?," section "Designing for Performance and Compatibility."

How to Handle International Issues

Refer to "Visual Basic® Programmer's Guide," part 2: "What Can You Do With Visual Basic?," section "International Issues."

Copyright  © 1987 - 2001 Rational Software Corporation


Display Rational Unified Process using frames

Rational Unified Process