How to represent a C# property in UML?

后端 未结 12 706
夕颜
夕颜 2020-12-08 19:03

Not quite an Attribute, not quite a Method. Stereotypes? <> <>?


I\'m retro-modelling an existin

相关标签:
12条回答
  • 2020-12-08 19:52

    Eh, I just throw it in as a method in my pseudo-UML diagrams. :-)

    0 讨论(0)
  • 2020-12-08 19:52

    The problem with depicting a property as a single field is that for C# using the 2.0 framework and beyond the get and set can have different access modifiers.

    0 讨论(0)
  • 2020-12-08 19:55

    I'd put them as public fields in UML, because that's what they are conceptually. UML is not a syntax for your programming language (although some tool vendors claim that it is).

    The details on how your implementation language handles properties don't need to show in the UML. This would entirely defeat the point of using UML as a tool that abstracts away the implementation details and lets you focus on design.

    If the property is special in some way, such that it is derived or read-only, you can mark that with a stereotype annotation.

    0 讨论(0)
  • 2020-12-08 19:56

    I usually prepare my UML diagrams in Visio (I know, I know; but what're ya gonna do?).

    When diagramming properties, they end up as so:

    +------------------------+
    | MyClass                |
    |------------------------|
    | - _foo : int           |
    |------------------------|
    | «property» + Foo : int |
    +------------------------+
    

    «property» being a custom stereotype derived from «operator».

    Ugly, I know. But it works, and it's clear. I do constructors the same way.

    0 讨论(0)
  • 2020-12-08 19:58

    In Visio you can create a <<readonly>> stereotype for Attribute and just use this stereotype for each read-only attributes. Same for write-only. It'll show you a good notation:

    <<readonly>> +PropertyName : int
    

    There is nothing ugly about it. The standard Visio's Changeable option is much more uglier in that it has no any visual representation and you actually need to open properties for each attribute in order to see it, no chances to see it on the printed diagram.

    0 讨论(0)
  • 2020-12-08 20:07

    You could use a stereotype called "property"(eg. << Property >> PropertyName) for a field in your class diagram. Stereotypes are used to extend UML notation.

    0 讨论(0)
提交回复
热议问题