Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Architecture
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
Bing
BizTalk
Book Excerpts
Build and Deploy
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Design Patterns
Development Process
Display Technologies
Distributed Computing
DotNetNuke
DSL
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
Internet Explorer 8.0
Interviews
iPhone
Iron Ruby
Java
Java Script
jQuery
LINQ
Linux
Mac OS X
MDX
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
Network
NHibernate
Object Oriented Development
Odata
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Python
Q&A
Rails
Rake
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Search
Security
Services
SharePoint
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
Tips
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WF
Whitepapers
Windows 7
Windows Azure
Windows Live
Windows Server
Windows Vista
WinForms
Workflow
WPF
XAML
XML
XNA
XSLT



Virtual Brown Bag Lunches


 


INSTANTLY dtSearch® TERABYTES OF TEXT

Reader rating:
Click here to read 3 comments about this article.
Article source: CoDe (2004 - September/October)


Article Pages:  1  2 - Next >


Visualize Your Code with the Class Designer

The Class Designer feature of Visual Studio 2005 allows you to visually manipulate your classes. A picture is worth a thousand words, as the saying goes. The new Visual Studio 2005 (Whidbey) Class Designer provides a visual design environment that allows you to visualize and manipulate your classes. Being able to see your classes and work with them using a visual designer can significantly increase your productivity.

Using the Class Designer

You can use the new Visual Studio 2005 Class Designer feature to visualize your code. You can also use it to create new classes, update existing classes, or easily refactor your application.

"
The Class Designer does not perform a round trip. It does not actually "trip" at all. Rather, it is simply another view of the same data.
"

If you have access to a Community Technology Preview (I used the May 2004 edition), you can work through the examples in this article and try out the Class Designer. If not, just follow along with the examples for an overview of the Class Designer's features.

Visual Studio provides the Class Designer as a project item. To create a class designer, right-click a project and select Class Diagram from the Add New Item dialog box. Then specify the name of the diagram. Visual Studio creates the item with the defined name and a .cd extension.

When you have a Class Designer open, the toolbox displays the items that you can insert onto the designer as shown in Figure 1. Drag an item from the toolbox to the design surface to add the item to the designer.

Click for a larger version of this image.

Figure 1: The Class Designer toolbox provides the symbols that you use to build your class diagram.

There are several different types of items that you can add to the designer including a class, structure, interface, and enumeration. You can also add relationships and comments.

As an example, let's create the class diagram for an application that processes orders. To keep the diagrams simple for this article, the application will have a Customer class, an Order class, and an OrderDetail class.

To show that this feature works with multiple languages, I'll create the Order and OrderDetail classes using VB and I'll create the Customer class using C#.

Begin by creating a VB project. Then add a Class Designer project item using the Add New Item dialog box and name it Order. Visual Studio displays an empty design surface for the class diagram. Drag the Class item from the toolbox and drop it onto the design surface. The New Class dialog box prompts you to enter the class name, file name, and desired class accessibility (public, private, and so on). For the Order class, name the class Order and give it Public accessibility.

Drag another Class item from the toolbox and drop it onto the design surface. In the New Class dialog box, name this class OrderDetail and give it Internal accessibility. The OrderDetail class will only be accessible from within the other classes of this project.

Because the two classes are related, the next step is to draw the association between the classes. Click on the Association item in the toolbar. The cursor changes to an association symbol. Click on the Order class first and then click on the OrderDetail class to define the association. The result is shown in Figure 2.

Click for a larger version of this image.

Figure 2: The Class Designer displays the classes of your application along with their relationships.

For a class to have any usefulness, it needs to have some functionality. You can add methods, properties, fields, or events to the classes. Add a CalculateTotal method to the Order class that will calculate the total cost of the order. Right-click on the class and select the Add context menu or use the Class Details window that appears at the bottom of the Visual Studio editor when a class is active on the design surface as shown in Figure 3.

Click for a larger version of this image.

Figure 3: The Class Details window allows you to define the methods, properties, fields, and events for your class.

Notice that the Class Details window displays an OrderDetail property in the Order class. The Class Designer automatically created this property when you defined the association between the Order and OrderDetail classes.

Now let's create a C# project in the same solution as the VB project. Follow the same process for creating a Class Designer and name it Customer. Drag the Class item from the toolbox and drop it onto the design surface to create the Customer class.

NOTE: When using C# with the May preview, Visual Studio generates an exception when attempting to use the Class Details window to add properties or methods or when you attempt to use the Association item.

You can use the resulting class diagrams as a way to communicate your application's design. You can print them, you can save them as an image and post them on your developer Web page, or you can include them in a presentation.

&

By: Deborah Kurata

Deborah Kurata is cofounder of InStep Technologies Inc., a professional consulting firm that focuses on turning your business vision into reality using Microsoft .NET technologies. She has over 15 years of experience in architecting, designing and developing successful applications.

Deborah is the author of several books, including Best Kept Secrets in .NET (Apress), Doing Objects in Visual Basic 6.0 (SAMS) and Doing Web Development: Client-Side Techniques (Apress). She is on the INETA Speaker’s Bureau, is a well-known speaker at technical conferences, and is a Microsoft Most Valuable Professional (MVP). After a hard day of coding and taking care of her family, Deborah enjoys blowing stuff up (on her XBox of course).

Some of the information in this article was obtained from her upcoming book, Doing Objects in VB 2005.

deborahk@insteptech.com

Fast Facts

The Class Designer in Visual Studio 2005 allows you to visually manipulate the classes of your application. Changes made to the diagram are reflected in the associated code.



Article Pages:  1  2 - Next Page: 'Viewing the Associated Code' >>

Page 1: Visualize Your Code with the Class Designer
Page 2: Viewing the Associated Code

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.8 out of 5

28 people have rated this article.

      QCon

 

DevReach