1

I am creating a uml diagram to help me better understand some source code that was written by a third-party. When creating my diagram, should I include both a private field and a public property where auto-implemented properties are used as in this case:

-name : string
+Name : string

Or should I just use the public property in the diagram:

+Name : string

jaromey
  • 666
  • 2
  • 10
  • 27

2 Answers2

3

In UML relationships between classes are of greater importance than their attributes such as variables, properties and methods. That is why you should omit private variables to make diagram concise. If public property X of class A is used by class B, make it concise: show that B uses A: draw an arrow from B to A without showing property.

class A
{
    public int X { get; set; }
}

class B
{
    public int Twice(A a) 
    {
        return a.X * 2;
    }
}
myroman
  • 532
  • 5
  • 11
1

...uml diagram to...better understand some source code...third-party...should I include both a private field and a public...

Focus on the level that's important for you.

Personally I'd go on with the results of UML classes created by automatic code reverse engineering (EA, doxygen UML_LOOK, ...)

For some discussion of what's appropriate see also Stack Overflow: How to represent a C# property in UML?

Community
  • 1
  • 1
xmojmr
  • 8,073
  • 5
  • 31
  • 54
  • Thank you for pointing out that tool. I actually was not aware of it. It might help me save some time. – jaromey Mar 20 '15 at 14:46
  • @Jslick I'm not sure how does the `C#` to `UML` tool market look like today. I'm satisfied `Enterprise Architect` user and I have used successfully `doxygen+graphviz` to generate documentation and some `UML` diagrams from `C#`, `Java`, `C++` code. But there's also some `UML` modeling support right in the `Visual Studio` (Ultimate?) and the `NDepend` tool can also provide valuable point of view at (huge) 3rd party code base. Finding or recommending a tool is not on-topic on Stack Overflow so you'll have to search for good recommendations somewhere else – xmojmr Mar 20 '15 at 15:30