Book a Demo

Author Topic: When is a Property not a Property?  (Read 9402 times)

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
When is a Property not a Property?
« on: October 19, 2005, 05:52:25 am »
In another post [size=13]Exposing properties through an interface
[/size]
I expressed the view that if you had a coding language Property for which you only had a simple setter and getter, you might as well use Public Attribute.

I was basically saying that coding language Properties are just Operations masquerading as Attributes.

So I thought I'd check out the UML official position on Properties.

I found the UML 2 [size=13]Superstructure[/size] Specification section 7.3.44 discusses Property.  But it seems pretty clear to me that this (UML) Property is NOT the same as the language Property in the thread above.

Can anyone confirm this?  
What's the best way to model the language Property?

And while we're at it, the ostensible definition of a Property as the "public interface to a private variable" is patent nonsense since no variable needs to be referenced in the property at all!

Paolo

Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

SF_lt

  • EA User
  • **
  • Posts: 216
  • Karma: +1/-0
  • The Truth Is Out There
    • View Profile
Re: When is a Property not a Property?
« Reply #1 on: October 19, 2005, 06:18:10 am »
I agree, that coding languages mimic properties as attributes with assigned operations
registertm everything to SparX

mikewhit

  • EA User
  • **
  • Posts: 608
  • Karma: +0/-0
  • Accessing ....
    • View Profile
Re: When is a Property not a Property?
« Reply #2 on: October 19, 2005, 06:51:18 am »
Perhaps "private value" would be better then, since no "variable" is required to be involved.

However, I seem to remember an earlier discussion on this ... http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.pl?board=general;action=display;num=1084542865


jeshaw2

  • EA User
  • **
  • Posts: 701
  • Karma: +0/-0
  • I'm a Singleton, what pattern are you?
    • View Profile
Re: When is a Property not a Property?
« Reply #3 on: October 19, 2005, 08:21:31 am »
The way I read 7.3.44, Property (of a classifier) relates to the values that an attribute may take on, not the attribute itself.  It also relates to an object's state by virtue of the current value in a named slot.

One of my properties is that I'm Blond, not that I have a Human:hairColor slot.  It would be difficult to expose my blondness through an interface.  In the interface specification, I could only expose the requirement that a classifier (implementing this interface) has a specific named attribute and/or getter & setter operations.

Thus, a property specification is an enumeration of possible states and would best be modeled as an enumeration or dynamically, perhaps, as a State Transition diagram.

Verbal Use Cases aren't worth the paper they are written upon.

mikewhit

  • EA User
  • **
  • Posts: 608
  • Karma: +0/-0
  • Accessing ....
    • View Profile
Re: When is a Property not a Property?
« Reply #4 on: October 19, 2005, 08:45:04 am »
Some of the other discussions get confused because they refer back to "programming language properties" - Delphi and C# .

[Incidentally, what does the Italian word for "#" mean: "little gate" - wonder if Bill liked this name :-)]

thomaskilian

  • Guest
Re: When is a Property not a Property?
« Reply #5 on: October 19, 2005, 12:58:47 pm »
Little gate or little fence?

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Property Redux
« Reply #6 on: October 20, 2005, 06:15:48 am »
Properties Redux

Well, thank you all for your input on Properties.  There seems to be a lot of "Guff" written on Properties.  As far as I can make out the following statements are valid:

In the following the term Property means an construct similar to a C# Property or a Visual Basic Property.  It is not a requirement that the Property be part of a Class (as some languages have Properties, but not Classes).

--------------------
I define a Property as a construct that looks like an Attribute (or Field, or Variable, or structural feature) to the client, but whose value is actually accessible through at least one and up to two specific accessors defined by the supplier.  The accessors are known as the setter and getter (Operations, methods, behavioural features).

Where a Property is read only, a setter is not required.  It is possible to create a write only attribute; in which case, a getter is not required.

In order for the Property to behave like an attribute for both setting and obtaining a value, the name of the Operation must be the same for both the setter and getter.  Their signatures will, however, be different:
In order for the Property to behave like an attribute for obtaining a value, the getter (Operation) cannot have a parameter.  In order for the Property to behave like an attribute for setting a value, the setter (method) must have exactly one parameter (the value).

Properties are defined in terms of a Name and Type (just like an Attribute).

There is no requirement for a Property to be bound in any way to an other Attribute or Property.

Not every programming language has the Property Construct.  In particular, Java attempts to simulate the property construct by means of Operations with specifically formatted naming.  These Java constructs are not true Properties and are contentious (see [size=13]Why getter and setter methods are evil[/size])

Although Properties are often used to "provide a Public Interface to a Private Attribute", this is just one usage.  The Property may have arbitrary visibility (just like any other Attribute).  The visibility of the Property applies equally to the accessors.

UML derived Attributes can only properly be instantiated using a read-only Property.
--------------------

Here is what Microsoft has to say in the documentation for the PropertyInfo class:

"Properties are logically the same as fields. A property is a named aspect of an object's state whose value is typically accessible through get and set accessors. Properties may be read-only, in which case a set routine is not supported."

Paraphrasing Programming C# by Jesse Liberty

"... Properties ... act like methods to the creator of the property but look like fields to clients of the property.

Properties allow clients to access the property as if they were accessing fields directly, while actually implementing that access through two methods.

Properties provide a simple interface to the client, appearing to be a field.  They are implemented as methods, however, providing the data hiding required by good object-oriented design."

What does this mean for UML modelling of such Property constructs?

It seems to me that in order to correctly round-trip such constructs the Property must ostensibly appear to be an Attribute.  Fortunately, EA seems to agree thus far.  You can designate an Attribute as a Property.

Secondly, the Property must specify where it has read or write accessors.  EA also concurs.

The visibility of the Property defines that of the accessors.  EA (incorrectly in my view) allows this to variable.  However proper modelling discipline will solve that.

The name of the accessors must be the same as the Property (pseudo Attribute) (if exposed - such as with some forms of Basic).  EA allows separate naming, discipline will help.

The Property must allow the definition of the appropriate accessor bodies.  Unfortunately EA does not support this.  For the present, I'd advise creating the two accessor Operations with the same name as the Property Attribute - the getter with no Parameter, but returning a value of the same type as the Property Attribute; and the setter with exactly the one Parameter of the same type as the Property Attribute.

Where a Property actually interacts with one or more other Attributes or Properties, it would be nice to be able to record this dependency.  In particular, where a Property is simply used to set and get another Attribute, one could have a checkbox so indicating that and a link to the bound Attribute or Property.  The accessor bodies could then be generated without further input.

Thoughts anyone?

How about it Sparxians?

Paolo
[size=0]©2005 Paolo Cantoni, -Semantica-[/size]
« Last Edit: November 01, 2005, 04:12:33 am by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!