views:

1963

answers:

6

These seem to mean the same thing. But what term is more appropriate in what context?

A: 
<property attribute="attributeValue">proopertyValue</property>

would be one way to look at it.

In C#

[Attribute]
public class Entity
{
    private int Property{get; set;};
dove
Sorry to vote this down but in XML what you labeled a property is actualy an "element"
Harald Scheirich
+2  A: 

No difference. Just fashion. But you aren't the first to wonder about this. Google "attribute versus property".

Corey Trager
This is false in a C# context as you can see per answer just below.
Will Marcouiller
A: 

Delphi used properties and they have found their way into .NET (because it has the same architect).

In Delphi they are often used in combination with runtime type information such that the integrated property editor can be used to set the property in designtime.

Properties are not always related to fields. They can be functions that possible have side effects (but of course that is very bad design).

Gamecat
Not necessarily. Automated dirty checking on a persistent object would be an example of a property with side effects that wouldn't be bad design.
Quibblesome
+1  A: 

In Python...

class X( object ):
    def __init__( self ):
        self.attribute
    def getAttr( self ):
        return self.attribute
    def setAttr( self, value ):
        self.attribute= value
    property_name= property( getAttr, setAttr )

A property is a single attribute-like name that wraps a collection of setter, getter (and deleter) functions.

An attribute is usually a single object within another object.

Having said that, however, Python gives you methods like __getattr__ which allow you extend the definition of "attribute".

Bottom Line - they're almost synonymous. Python makes a technical distinction in how they're implemented.

S.Lott
+5  A: 

The precise meaning of these terms is going to depend a lot on what language/system/universe you are talking about.

In HTML/XML, an attribute is the part of a tag with an equals sign and a value, and property doesn't mean anything, for example.

So we need more information about what domain you're discussing.

Ned Batchelder
A: 

In Java (or other languages), using Property/Attribute depends on usage:

  • Property used when value doesn't change very often (usually used at startup or for environment variable)

  • Attributes is a value (object child) of an Element (object) which can change very often/all the time and be or not persistent

eric