Book a Demo

Author Topic: C# Properties  (Read 18287 times)

Jeff Odell

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: C# Properties
« Reply #15 on: November 23, 2004, 06:25:23 am »
Where does it say a class' attributes have to be implemented as storage locations?  If I have an internal collection, and I have an property returning it's count, are you Ok with that as an attribute as it refers to something stored within the object?

When I expect the user of the class to get or set a single value in an object, I implement a property.   To the user it is transparent how that state is maintained.  When I want an action to occur, I create a method. The user can then expect some action to occur.

So I still want propertied to represent a UML attribute of an object.  

I only asked for the option so we could all be happy.  :)

ceatley

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: C# Properties
« Reply #16 on: November 23, 2004, 09:25:39 pm »
I also use properties as though they were attributes, but they have a direct one - to - one behavior correlation with operations.

if
public type property
{
 get {
  any code that returns a value of type
}
 set {
   any code that changes the value of a variable of type
}
}
then    
  type x = property is <=> with type x = get_property();

and
  property = x is <=> with set_property(x);

The point is that properties also have the same limitations as operations  (ie can't be used as ref and out parameters)
98% of the time it doesn't make a difference, but when it does, it will bite you.   There are several other places where you will get into trouble if you try to use a property as an attribute.  I have spent more then a little time changing code when I forgot and used properties incorrectly.

I therefore think that the way the reverse engineering is done now, gives a better view of what is happening.  Sometimes, information hiding isn't the best answer.

Chuck
« Last Edit: November 23, 2004, 09:37:59 pm by ceatley »

Hans

  • EA User
  • **
  • Posts: 78
  • Karma: +0/-0
    • View Profile
Re: C# Properties
« Reply #17 on: November 28, 2004, 11:08:27 am »
But: Every field is translated into IL-properties upon compilation.

Jeff Odell

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: C# Properties
« Reply #18 on: November 29, 2004, 05:16:20 am »
I just have to disagree - mapping a property directly to a field is just one implementation of an attribute.  The fact that I might to write code to derive the value of an attribute, and that code might be wrong, doesn't change that.

In my mind, a property is never an operation, because if it does something, rather than just change the state of something, I code it as an operation anyway - i.e. a C# method rather than a property.

Again - I just want the option to map a property to an attribute in EA.  I had asked for the ability to flip a switch in code generation to set the default.  Perhaps this should only be the default, with the ability to set individual properties to appear as attributes or operations based on a tag or something.  This would allow you the flexibility to decide which properties are attributes and which are functions.  I would be disinclined to use that feature - to me they would all be attrbiutes - but if you wanted to designate them you'd have that flexibility.

jlo

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C# Properties
« Reply #19 on: November 29, 2004, 01:28:35 pm »
Hi,

I've noted that an option to reverse engineer C# properties as properties or methods would be appreciated.  The same would I assume apply to VB.Net although that hasn't been discussed yet.

I'll look into how hard it would be to do this along with everything else that I am doing.  Default behaviour would probably be the existing behaviour.

Simon

inthere

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: C# Properties
« Reply #20 on: November 30, 2004, 02:27:36 am »
To me it is clear. An attribute is something that is operated on by operations. An operation is something that can modify the state of an attribute. A C# property can operate on an incoming or outgoing attribute value, therefore is must fall under the operation category.

Paul
Thanks, Paul

ceatley

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: C# Properties
« Reply #21 on: November 30, 2004, 11:46:27 am »
OK, if a property is modeled as an attribute, how is the code generated?  Also, if a property model named Count accesses a private attribute named count, how do you model the association?

Jeff Odell

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: C# Properties
« Reply #22 on: November 30, 2004, 12:44:25 pm »
You can already create properties in the attribute section of the model - create an attribute and attach the "property" stereotype.  When you generate code you get:

Code: [Select]

public string Ssn {
   //read property
   get{;}
   //write property
   set{;}
}


That works fine for me.  

What I'd like is the opportunity to have reverse engineering reversing properties so they end up in the attribute section.

I don't understand the association question.

Jeff Odell

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: C# Properties
« Reply #23 on: December 02, 2004, 05:09:21 am »
Simon -

Yes - I'd really like the option for the reverse engineering to place the the properties in the attributes section.  Although I was thinking C# I do occasionally work in VB also so that would be great.

jlo

mikewhit

  • EA User
  • **
  • Posts: 608
  • Karma: +0/-0
  • Accessing ....
    • View Profile
Re: C# Properties
« Reply #24 on: December 02, 2004, 07:33:14 am »
Note that you can specify a class attribute to be 'derived' (which is close-ish to a C# property) which makes it display with a '/'.

I don't know how this affects code generation.