In the JavaBean section of my revision list it states that I should know "the difference between an attribute and a property". I can't really find a difference between the two. I'm aware that JavaBeans use properties and normal Java classes use attributes (or at least that's what I was taught to call them) but I can't see a real difference.
Is it to do with getter/setter methods?
Thanks
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
age
translates to personAge
attributeprivate int personAge;
public int getAge() {
return personAge;
}
public void setAge(int age) {
this.personAge = age;
}
In this case the property is read-only:
private int age;
private Sex sex;
public boolean isFemaleAdult() {
return sex == Sex.FEMALE && age >= 18
}
I found few intereseting hints in Tapestry documentation:
A property is not the same as an attribute ... though, most often, each property is backed up by an attribute.
and later:
Another common pattern is a synthesized property. Here, there is no real attribute at all, the value is always computed on the fly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With