.NET
  Home arrow .NET arrow Page 2 - Examining the UML Models: Static Models
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Examining the UML Models: Static Models
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 11
    2005-04-20

    Table of Contents:
  • Examining the UML Models: Static Models
  • Classes
  • EXERCISE 5-4
  • EXERCISE 5-7
  • Relationships
  • Generalization Relationship
  • States
  • Components
  • Dependencies
  • Code Generation from a Component Diagram
  • Nodes
  • Stereotypes
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Examining the UML Models: Static Models - Classes


    (Page 2 of 13 )

    The next step in your class diagram modeling is to place the classes on the diagram. You can drag the classes from the Shapes window onto the diagram, or you can right-click the package in which you want your new class created, and then choose New -> Class from the pop-up menu. If you create a new class in a package, it’s automatically related to that namespace (package). If you double-click a class, you’ll see the UML Class Properties dialog box, as shown in Figure 5-5.


    Figure 5-5.  UML Class Properties dialog box for the Customer class

    The basic settings for a class are the class name and optionally a class stereotype. We’ll cover the stereotype concept in the “Stereotypes” section later in this chapter. For now, just consider stereotypes as a way of specifying a commonly occurring subtype of an element. For instance, your class can be of the stereotype COM+, indicating that it’s a class specialized to type COM+.

    Classes are represented by a box shape, which is divided into three parts:

    • Name

    • Attributes

    • Operations

    The name part is self-explanatory. The following sections describe the attributes and operations.

    Attributes

    Attributes are also known as properties in .NET development. You specify the attributes for the class by selecting Attributes from the Categories list of the UML Class Properties dialog box (see Figure 5-5). In Exercise 5-2, you’ll specify attributes for the Customer class. We’ll make the Customer class attributes public, in order to make them accessible to the users of the class.


    EXERCISE 5-2

    1. Open the UML Class Properties dialog box for the Customer class by double-clicking the class.

    2. Select the Attributes category.

    3. Click New to create a new public attribute named Name, of data type VB::String. (You would make the type C#::string, if you wanted to code in C#.)

    4. Click New to create a new public attribute named Address, of data type VB::String (or C#::string for C# code). Figure 5-6 shows the attributes set for the Customer class.


    Figure 5-6.  UML Class Properties dialog box with attributes for the Customer class

       5.  You can generate new code for the Customer class by selecting 
            UML -> Code -> Generate. In the Generate dialog box (shown
            earlier in Figure 5-2), choose Visual Basic as the target    
            language, check the Customer check box, specify the path as
            \EDWVSNETUMLMSF\Chapter 05\, and click OK. VEA then
            generates the code, as shown in Figure 5-7.


    Figure 5-7.  Generated code for the Customer class with attributes


    After you’ve generated the code, you’ll notice that there are now two VB code files: Customer.vb and Customer~1.vb. The newest generated file will be Customer.vb. VEA renames existing files with a tilde and number: Customer~1.vb, Customer~2.vb, and so forth.

    Stateless Classes

    If a class has attributes, it must keep an instance in memory of every single class instantiation in order to save the attribute values. A class doing this is known as a stateful class. Stateless classes are better for scalability than stateful classes.

    Keep in mind that when you’re developing enterprise solutions, performance and scalability are always issues. Classes should be stateless. This applies to all kinds of classes, regardless of whether they are COM+ classes, VB/C# classes, Web services, or other kinds of classes. Actually, Web services assume a stateless programming model, although state can be added to a Web service.

    If your components must maintain state, the state information can be stored in a database such as SQL Server, or even in a simple text file. If your component is an ASP.NET Web service, you can store state using the built-in ASP.NET functionality for state, using the Session and Application objects.

    In the old days (before .NET, that is), Microsoft encouraged developers to use the Shared Property Manager (http://msdn.microsoft.com/library/ default.asp?url=/library/en-us/cossdk/htm/pgservices_spm_5stu.asp) to store state. The Shared Property Manager functionality is still available in .NET through the System.EnterpriseServices namespace, which provides you with important infrastructure for enterprise applications. However, the Shared Property Manager does not do well when it is accessed heavily, especially in enterprise environments with multiple processors and servers. This is simply because it doesn’t scale very well. Microsoft suggests that you do not use the Shared Property Manager for storing database connection string information, which will be accessed frequently. We recommend storing state in the database, rather than using the Shared Property Manager.


    Operations

    Operations are often referred to as methods. Technically, the operation is the interface, and the method is the code, but these terms are often used interchangeably. In UML class modeling, an operation can be one of the following .NET types:

    • Constructor

    • Destructor

    • Event3

    • Procedure

    • Property procedure

    You specify the operations for the class by selecting Operations in the Categories window of the UML Class Properties dialog box (shown earlier in Figure 5-5). In Exercise 5-3, you’ll specify operations for the Customer class.


    EXERCISE 5-3

    1. Open the UML Class Properties dialog box for the Customer class by double-clicking the class.

    2. Select the Operations category.

    3. Click New to create a new public operation named GetList, of data type VB::Object (C#::object if you want to code in C#).

    4. Click New to create a new public operation named CustomerStatus, of data type VB::Boolean (C#::bool if you want to code in C#).

    5. Click New to create a new public operation named New. This will be our class constructor. (If you want to code in C#, the name doesn’t matter; the code generator will ignore it and name the constructor after the class.)

    6. Click New to create a new public operation named Finalize. This will be our class destructor. (Again, If you want to code in C#, the name doesn’t matter, because the code generator will ignore it and name the destructor after the class.) Your dialog box should look like Figure 5-8.


    NOTE In general, you don’t need to override the default destructor in your .NET classes. You would need to do this only when you need to perform some sort of housekeeping, such as destroying any references to classes in COM components. However, we create a class destructor in this example, just to demonstrate how it is done.


    Figure 5-8.  UML Class Properties dialog box with operations for the Customer class

      7.  Click OK.

    The GetList operation is a method that provides you with a DataSet of all customers of a certain type. You specify the type via a parameter setting when calling the operation. You specify that an operation expects a parameter via the UML Operations Properties dialog box (which appears when you select the operation and click the Properties button in the Operations category of the UML Class Properties dialog box). In Exercise 5-4, you’ll specify a parameter for GetList.


    More .NET Articles
    More By Apress Publishing


     

    Buy this book now. This article is excerpted from Enterprise Development with Visual Studio .NET, UML, and MSF written by John Erik Hansen and Carsten Thomsen (Apress, 2004; ISBN: 1590590422) Buy this book now.

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek