Advantages of Using Class Diagram

misc_vol4_063 One of the new tools that showed up in Visual Studio 2005 that I don’t see many people taking much advantage of is the Class Diagram.

The class diagram displays the classes you drag onto it in a visual representation much like a UML class diagram does.  It also lets you see relationships between your classes.  But the greatest power in the Class Diagram is that it will write a lot of your code for you.

The Class Diagram is available in both CSharp and VB.NET and works similarly in both.  My description of the tool will be using CSharp in Visual Studio 2008.  There may be a few quirky differences if you are using VB.NET and/or Visual Studio 2005.

I was reminded of this tool a couple of days ago when I needed to override a method but I couldn’t remember its name.  I could have spend a few minutes looking in the parent class for the name of the method I needed to override, but instead I created a new Class Diagram file and did a drag and drop of the class I was working on onto the Class Diagram’s surface.  This then let me right-click on the class and select “Intellisense” > “Override members…” from the context menu.

This will bring up a dialog that will list ALL of the classes the class inherits from (so it helps to know what class the method you want to override is in).  You can then check off the members you want to override from the list supplied.  When you press OK, the methods will be stubbed out for you in the source code.  All you need to do is provide the functionality.

You can use this same type of process to add new methods, add properties, and add member variables.

If you haven’t broken out the class diagram recently, I suggest you give it a try.


Other post in Did you know

Related Post

  • Readable CodeReadable Code Time out today for just a bit of a rant. A couple of days ago, I posted a top ten list for why you shouldn't buy Visual Studio 2008.  Most people totally got that this was all tongue in cheek.  ...
  • Object Initialization in CSharp 3.0 and VB.NET 9Object Initialization in CSharp 3.0 and VB.NET 9 Yesterday we looked at the new var keyword in CSharp.  This makes CSharp variable declaration similar to VB.  After all, they've had the DIM keyword for years which essentially does the same thing....
  • Anonymous TypesAnonymous Types So, let's get to work looking at anonymous types in .NET. As you know, last week we looked at object initialization.  Object initialization allows us to instantiate an object and assign pr...
  • How to code LINQHow to code LINQ Today we finally put all the code we've been looking at for the last couple of weeks into practice and take a look at LINQ.  Today's example will be relatively brief but once you understand the und...
  • Lambda Expressions. Other than LINQ…Lambda Expressions. Other than LINQ… ... what are they good for? If you haven't caught on yet, I'm inching my way toward LINQ. By the time I get to it, it will probably be about a 5 - 10 minute presentation just like the ot...
  • Pingback: Dew Drop - November 20, 2008 | Alvin Ashcraft's Morning Dew

  • Pingback: Arjan`s World » LINKBLOG for November 22, 2008

  • sangam uprety

    Yeah, I agree. The use of class diagram can mean a lot. Mainly if we plan to develop business objects and design sort of layer architecture in .net applications. I have the experience that it takes so many time to manually code the class objects. Hope i would be inspired to go for class diagrams [I think I almost ignored it in my two years programming career]. THank you for the post.