2017-11-14 1 views

Antwort

-1

Die attribute und property Begriffe sind Synonyme in den meisten Fällen (auch member, field), obwohl property ist oft (python, C#, pascal, usw.) verwendet, um das "virtuelle Attribut" zu beschreiben, die tatsächlich von get/set umgesetzt wird Methoden (und attribute wird für reguläre Attribute verwendet).

Zum Beispiel (Python-like Pseudo-Code):

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 

Hier haben wir zwei "echte" Attribute - first_name_attribute und last_name_attribute und eine "virtuelle" Eigenschaft - full_name.

Verwandte Themen