1
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ Duplicate: See this question, its answer and the linked packages for a detailed discussion/implementation of OOP in Mathematica. $\endgroup$
    – rm -rf
    Apr 16 '13 at 17:47

This site is temporarily in read only mode and not accepting new answers.

Browse other questions tagged .