> Hi,
>
> I know sounds silly, but what is the difference
> between Property, Attribute and Parameter? In what
> cases every of this words is used?
>
> Anton
Property: I use this word sometimes to refer to some property in a properties file. I can be used in XML, too. In a XML file you have properties.
Attribute: For me, it can have many meanings! I don't think that this word can have a specific meaning in programming. I'm not sure if this word can be used when you want to talk about some XML file. I think it can be used, yes.
Parameter: I use this word to refer to the parameter(s) of some method.
Besides the very general meanings of those words, and the ones already mentioned, contexts in which you might be getting them confused could be:
Property: In a Javabeans context, refers to the abstract notion of one element of an object's state. Most commonly maps to a single instance variable that is accessed with get/set methods. Because of this, "property" might also be used to refer to that variable. However, in a Javabeans context, the two have different meanings, they just happen to often map directly to one another.
Field: An instance variable. (You didn't mention this one, but it pops up in the same contexts.)
Attribute: I'm not sure what the formal defnition is for this one, but I seem to see it used much like property, though related more closely to an object in a general sense than in a Javabeans sense. Basically an element of the object's state, or the instance variable that holds it.
Parameter: Totally different from the above. This is a variable that accepts input values to a method call, or possibly the value of that variable.
class Foo {
private Bar bar_;
public Bar getBar() {
return bar_;
}
public void setBar(Bar bar) {
bar_ = bar;
}
}
Here's how I'd view it:
The class has one attribute, bar_, that is stored in the instance variable bar_. (This is the one I'm fuzziest on.)
The Javabean represented by this class has one property, bar, that is stored in the instance variable bar_. (This is pretty solid Javabeans terminology.)
The class has one field, bar_. (This is pretty solid, but there migt be a subltety I'm missing.)
The setBar method has one parameter, bar. (This is quite solid.)
Parameter is pretty well fixed, at least in a Java context. The others tend to be used more loosely, I think.
> Property: (...) in a Javabeans context, the two have different meanings,
> they just happen to often map directly to one another.
> Attribute: (...) Basically an element of the object's state,
> or the instance variable that holds it.
I second the main point there is an important difference between the two meanings: the abstract specification of observable state, and the implementation of it. And I agree with jverd's commented example for the usage of the terms.
As far as evocative terminology goes, the terms field and instance variable clearly refer to the "implementation" meaning.
On the other hand, as jverd pointed out, attribute or property are used more loosely, and can refer to both meanings.
AFAIMC, I deem they illustrate more the first, abstract meaning. But that's an opinion, and there doesn't seem to be a general consensus.
I was formally taught in CS course that attribute related to the abstract meaning.
The idea being that if the type Person has an attribute Age, the implementing classes can implement this attribute however they like (value stored in an instance variable, computation using another field, database query,...).
I haven't found my teacher's definition to be widely accepted over the Internet or even across my local colleagues, but I like the distinction, especially to prevent misinterpretation such as "Hey this class has lots of attributes, so it must use up much room in memory!".
A word on Parameter: I fear to sound a bit pedantic, but it is indeed used to mean several different things:
- jverd pointed out the most usual use of the term, synonym of a method's argument. Indeed Sun favors this latter term, argument. Again I happen to have been taught this way too.
- Parameter is also used in the expression Type Parameter (cf generics), in which case it is important to make the distinction with the arguments.
- Last but not least, due to the meaning of the word in the general language, parameter will often refer to anything that influence the course of an algorithm. To various people it can mean a constant, a configuration value read in a file, a global variable, a method's argument, or a completely external factor (as in "The number of concurrent users is a parameter that will affect the load of your database").
> I was formally taught in CS course that
> attribute related to the abstract meaning.
> The idea being that if the type Person has an
> attribute Age, the implementing classes can implement
> this attribute however they like (value stored in an
> instance variable, computation using another field,
> database query,...).
>
> I haven't found my teacher's definition to be widely
> accepted (...)
1) Indeed the Eiffel language went so far as to implement this notion in its syntax: the following client code
int value = provider.att
makes no assumption as to whether the implementing class implements this as the reading of a field or the execution of a method. I think even the compiler doesn't know (one subclass may implement it either way, and another subclass the other way).
2) Thinking in such terms has a practical application in Java: specify your attributes as accessor methods. This enables implementing classes/subclasses to implement them the way that fits best, and also to change mind over time : indeed this is a good practice which makes the code more flexible (think about refactorings).
> A word on Parameter: I fear to sound a bit
> pedantic, but it is indeed used to mean several
> different things:
>
> ... etc. ...
Thanks for pointing that out. I should've known it wouldn't be that clear-cut. :-)
As for paramer vs. argument, I believe in CS there are definitions that relate one to the formal parameter (parameter, I think) and the other to the actual parameter (argument, I think), but I can never keep them straight, and I--and most people I know--tend to use parameter and argument pretty interhangeably when talking about "things you pass to a method."
> 1) Indeed the Eiffel language went so far as to
> implement this notion in its syntax: the following
> client code
> int value = provider.att
> makes no assumption as to whether the implementing
> class implements this as the reading of a field or
> the execution of a method.
I think C# does something similar.
Java et al:
An object is composed of attributes
attributes can hold a primitive or a reference
Attributes can be a method or a property
XML:
An element can have attribute (names) and (attribute) values
an element has an opening and a closing tag
attributes and values are inside the opening tag
<bodyelement attribute="value></bodyelement>
CSS:
selector.class { property:value; }
body.myclassname { left:5px; }
Clear to everyone?">
Hi,
I got similar question (but specifically in context of J2EE ), and came across to this link, which I thought might be helpful to you.
http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletRequest.html
I was looking for the differences between getParameter() and getAttribute().
Take care.