views:

679

answers:

4

We are attempting to use VS2008 Class Designer for a UML-like class diagram. However, when we create an "association" link between two classes, VS2008 is adding lines to our code! We do not want this.

One reason we don't want this is that our idea of association (via a collection parrameter, etc.) is different than VS2008. For example, we have the following types of association we would like to include in the class diagram:

  1. Class A is a property of Class B.
  2. Class A is inside a collection property of Class B.
  3. Class A instantiates and uses a property or method of Class B.

VS2008 seems to consider all relationships to be of type #1 and to force them into this model by re-writing the code. Is there anyway to use the VS2008 class modeling tool to more effectively accommodate all 3 types of associations?

UPDATE: I went with Visio, however I think there are some tools out there allowing UML modeling with round-tripping, including Enterprise Architect and possible VS2010.

+1  A: 

Use Visio. The class diagram designer in Visual Studio is designed to tightly integrate with your code and keep in synch with it.

CesarGon
The basic property/method syncing would be useful, but the association syncing seems to very narrowly define the concept of association.
alchemical
Well, terms such as "property" and "association" mean different things to different people, authors and standards. Visual Studio uses its own definitions. :-)
CesarGon
Yep, Visio turned out to be much better suited.
alchemical
+1  A: 

You should clarify. What do you mean "Class A is a property of Class B"? Do you mean that Class B has a property of type "A"?

That is not an association in UML terms - it's a dependency. In fact, all of your examples are dependencies, and not associations.


Do you mean:

public class ClassA {}

public class ClassB
{
    public ClassA Property1 {get;set;}
}

If this is what you mean, then I would read it as

Class B has a property named "Property1". Property1 is of type "ClassA".

In UML, this is not an association - it's a dependency.


I'll concede that there is a subset of the set of properties which do correspond directly to associations. In fact, my example above is a member of that subset.

A counter-example (and what I was thinking about) is:

public class ClassA {}

public class ClassB
{
    public ClassA Property1 
    {
        get {/* perform some arbitrary calculation, then return the result */}
        set {}
    }
}

I apologize for thinking about the general case, and not the specific case.

The real answer to the original question has already been given: the Class Designer is a Class Designer, not a UML Class Diagram tool. It uses a notation similar to that of a UML Class Diagram, but it is not a tool for producing a Class Diagram - it is a tool for designing a .NET class.

Contrast this with the UML Class Diagram available in Visual Studio 2010, which is UML first, and class design second.

John Saunders
#1 simply means that one class exists as a property of the other class. I'm not a UML expert, but I'm guessing that the VS2008 class designer is missing many features that would be needed to fully support UML.
alchemical
...That being the case, I suppose a question becomes, is there any UML class designer that integrates well with VS2008? (Open source is a plus)
alchemical
Can you give an example of what you mean, if my new example above isn't what you mean?
John Saunders
@John: -1, because UML does not talk about code, but about conceptual modelling. You cannot say what something would be in UML by looking at a piece of code. An association in UML can be effectively (and correctly) implemented in code in a variety of ways.
CesarGon
Please quote from the standard how an association can be used to model the return type of a property, or method.
John Saunders
@John: Precisely, the standard *does not* delve into code, and therefore I cannot quote from it on how to implement in code any of the concepts that it defines. It is up to implementers of UML to decide.
CesarGon
I believe you may be confusing dependency and association. I have never seen return type modeled using an association.
John Saunders
@John: I know UML very well. :-) I collaborate with ISO JTC1 SC7 in the standardisation of modelling languages and have reviewed drafts of the spec at various stages. I know well what the differences between a dependency and an association.
CesarGon
@John: Also, it is usually a conceptual model (a collection of classes, associations, etc.) what is refined into code, and not the other way around. This means that what's in UML gets implemented as code. Developers get to choose what code mechanism to use in order to implement an association, a dependency, or whatever. In any case, it is the association (or the dependency) what may be *implemented* as a return type, not the return type *modelled* as an association (or a dependency). Hope this makes sense; it's hard to describe without pen and paper! :-)
CesarGon
Sorry Cesar, John is right. Associations == properties/fields. You're talking about a dependency.
Josh Einstein
Well, actually, my example of a field-like property could be considered as an association. IOW, an association could be generated into code as a field, or as a property, depending on taste. This is not true for all properties, but for a simple one that's equivalent to a field, it is.
John Saunders
@Josh: That is incorrect. Saying "associations == properties/fields" is equating together two abstraction levels that are meant to be kept separate; that's precisely why we have different abstraction levels: to have the flexibility to make implementation decisions. If decisions were pre-made from conceptual modelling all the way down to implementation, then we could throw UML diagrams at the computer and no programming would be necessary. :-)
CesarGon
I now realize I know much less then when I asked the question...:->
alchemical
@Luft: I am sorry to hear that. You need to realise two things. First of all, Visual Studio's class designer is *not* UML compliant. Secondly, there are no correct or incorrect ways of modelling things: there are ways that are more or less useful for certain purposes. Refining a UML model (or any conceptual model) into code requires adding detail (and therefore information not previously contained in the model), and that is something that a tool cannot do. A human needs to do it by exercising cognition. :-)
CesarGon
A: 

Class designer is not a general purpose diagramming tool like Visio. It's the "winforms designer" for POCO classes. It'd be like putting a label on a form to act as an annotation but not wanting visual studio to actually create the label.

Josh Einstein
A: 

Visual Studio 2010 Ultimate support UML class diagrams as well as sequence, component, use case, and activity diagrams. Editing these diagrams won't affect your code. You can also create sequence, dependency graphs, and layer diagrams from code and edit them to focus on the areas that you want. Changes to these diagram also will not affect your code.

I've posted more links on my profile for more info.

Esther Fan - MSFT