0

Can someone carefully describe the nuance between "attributes" and "properties"? I find them used interchangeably at times, and as differentiators at others.

1 Answers1

-1

The attribute and property terms are synonyms in most cases (also member, field), although property is often (python, C#, pascal, etc) used to describe the "virtual attribute" which is actually implemented by get/set methods (and attribute is used for regular attributes).

For example (python-like pseudocode):

class MyClass:

    string first_name_attribute;
    string last_name_attribute;

    @property
    def full_name(self):
        """Getter method returns the virtual "full name"."""
        return self.first_name_attribute + " " + self.last_name_attribute

    @full_name.setter
    def full_name(self, string value):
        """Setter method sets the virtual "full name"."""
        first_name, last_name = value.split(" ")
        self.first_name_attribute = first_name
        self.last_name_attribute = last_name

Here we have two "real" attributes - first_name_attribute and last_name_attribute and a "virtual" property - full_name.

Borys Serebrov
  • 15,636
  • 2
  • 38
  • 54