tags:

views:

2011

answers:

9

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


I'm retro-modelling an existing system, so I need to clearly reflect that this is not the same as a readonly field or a methods pair (regardless of what the IL says), so I think I'll go with the stereotype, but I'll accept the language independant get set_ as a general solution. Thanks all for the sanity test.*

+1  A: 

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

unforgiven3
+1  A: 

properties are Get/Set methods wrapped up in some nicer syntax. Just put them in as methods, or create some new UML syntax for them :)

workmad3
+2  A: 

You can represent properties the same way as fields. To specify additional info like readonly or writeonly you can use

+Name:string {READONLY}

Hemanshu Bhojak
+6  A: 

Properties are just a convenient way of writing get_MyValue() and set_MyValue(value) allowing assignment rather than the normal method calling (using parenthesis).

What you are accessing is actually a .NET property, C# has its own syntax for accessing these. Since under the skin the real get_ and set_ methods are created, so you could simply show those methods (to make your UML language independent - e.g. make your UML equally applicable to a VB.NET developer)

... or as you have suggested, introduce your own stereotype!

Ray Hayes
+5  A: 

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.

Mike Hofer
this is basically what I'm going to do, but the convention for constructors is simply the classname as a method you know :)
annakata
A: 

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.

VoidPointer
A: 

I use like this

-memberThePropertyWillExpose
+memberThePropertyIsExposing

Well, comments on this are welcome if this is a right way !!

Kunal S
A: 

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.

anon
A: 

I agree with workmad3. Properties are just a trick make a get/set methods a little bi nicer. For that reason I think it should be saved as a two different methods. What is more in this case you can set a different access permissions for them

Szymon Sasin