Class Diagramming, UML, and Team System
I recently found out from
Brian Randell that the class diagramming support found in almost every edition of Visual Studio 2005 (standard and up) was inherited from
Team Edition for Software Architects. If you want to diagram a full blown..
- Application
- System
- Logical Datacenter
.. then you'll need Team Edition for Software Architects (or the full suite). But
the core class diagramming functionality was deemed so critical that it was pushed all the way back down into Visual Studio 2005 Standard! And it's the real thing, with complete two-way editing support and all of the other trimmings that are provided for the other diagram types in the Architect edition. Nothing was cut or hobbled. How cool is that?
I was reminded how nifty the class diagramming functionality is when I saw it used in
this sample implementation of a ZIP class for .NET 2.0. So I set out to duplicate that diagram. Here's how you do it:
First, right-click the class you want to create a diagram for in the Solution Explorer, and select
View Class Diagram.

This creates a new class diagram file
ClassDiagram1.cd in your solution (for this class, natch), opens it, and also opens the
Class Details tool window.

Let's remove the two class diagrams we don't want by right-clicking them and using their context menu. But be careful! Remember this is true, "live" two way editing. There's
Delete Code and
Remove Diagram. We don't want Delete Code. ;) Now, expand the two remaining classes:

Pretty cool, eh? And it gets better: you can CTRL+C these classes to paste them into other apps (Word, etc) as the pretty images -- exactly as shown here.
And again, although the class diagramming is a standard feature in Visual Studio 2005, it's identical to how Architect edition works for the other diagram types.
If you like the class diagramming, you'll totally dig the Application, System, and Logical Datacenter diagrams.
Now, these class diagrams are great, but
they aren't technically UML. UML is a more formal representation. If you're not familiar with UML, try these brief tutorials:
If you want UML diagrams in Visual Studio 2005, you can use the "Visio and UML Modelling" support included in every Team System Edition. However, it's not integrated into the normal install.
You'll need to install "Microsoft Office Visio for Enterprise Architects", which is in the \Visio folder of the product DVD.
Once you do so, you can use the
Project | Visio UML | Reverse Engineer command to create a new Visio document in your solution. All the UML functionality in Visio can be accessed, appropriately enough, via the UML menu:

Note that we
can generate code from our UML diagrams, but it's a far cry from the seamless and intuitive two-way support provided with the built-in class diagrams.
This version of Visio bundles the full palette of UML stencils, although there are
alternative, simpler UML stencils available for Visio as well:

Below this, you'll see the
Model Explorer, which contains the reverse-engineered bits of your code:

If I drag and drop the ZipEntry and ZipFile classes on the blank Visio document surface, I get a comparable
UML representation of these classes:

It's the correct UML representation of these classes-- but it's not nearly as pretty as the Visual Studio version. Clearly there's some overlap here.
So when do you use UML, and when do you use the Visual Studio Class Designer? Keith Short provides
some guidelines:
We recommend UML and UML-based tools for
- Sketching,
- White boarding,
- Napkins,
- Documentation,
- Conceptual drawings that do not directly relate to code.
We recommend [Visual Studio diagramming tools] for
- Precise abstractions from which code is generated
- Precise abstractions that map to variabilities in frameworks and components
- Precise mappings between DSLs
- Conceptual drawings that have precisely specifiable mappings to other DSLs or to code artifacts.
As a general rule, I think you're better off avoiding UML altogether, unless it's required on your project.