This question already has an answer here:
I'm trying to program using object orientation in Mathematica. For this i need to implement get and set methods. Lets consider that we are working with a person class, that have the fields name and height.So, a instance of the class is: p=person["John",1.74] (person[name,height]) The get methods can be implemented as follow: person/:getName[person[name_,height_]]:=name person/:getHeight[person[name_,height_]]:=height Trying the same approach in the set methods we would have: person/:setName[person[name_,height_],value_]:=name=value person/:setHeight[person[name_,height_],value_]:=height=value But in this, the set method will evaluate the person instance and will be not able to to make the assignment. If, however, we put the attribute HoldFirst in the set methods we will not be able to use the method, because, how the set methods have this attribute, it will not be able to recognize that the entry have the head person. So how can i do this?