I was wondering how to do it in general, what are the best strategies etc. I have seen some solutions and some of them look really hard/tedious to use. The one I worked on used pure functions to implement object functions and heads like OBJECT[]. It was very hard to use on the class coding side. I got dizzy when defining functions and constructors (especially the inheritance part was tough).
So the emaphsis of my quesiton is on the elegenace of the coding part of a class. Ideally, I am looking for something that would work as follows. First, we define a class, e.g. car as follows:
beginClass["vehicle"];
public startTheEngine;
private fuel;
vehicle[args_]:=Block[{},...];
startTheEngine[thrust_]:=Block[{}...];
endClass
beginClass["car", "vehicle"];
public TurnTheRadioOn;
private frequency;
car[args_] := Block[{...},];
TurnTheRadioOn[]:=
Block[{},
use private variable frequency
]
endClass;
Please note that it is very important that private/public functions are defined almost as in a "normal" mathematica code. This would the main requirement so to say.
The class would be used as
car1 = newObject["car", args];
car1.StartTheEngine[];
car1.TurnOnTheRadio[];
I am curious what is that one has to think about? To consturct something like the above probably involves many aspects of Mathematica, e.g. how would one fix the "." syntax etc. If you suggest an existing package I would be grateful if you could comment on how it works in principle.
My naive expectation is that the encapsulation part could be fixed by BeginPackage constructs. All objects could be stored in namespaces specifically designed for each class. I presume that objects would look like
car1 = OBJECT["car"][fuel$1,frequency$1,....];
car2 = OBJECT["car"][fuel$2,frequency$2,....];
I presume one would have to construct something like a compiler that would convert the class definition code above into the class .m file. Also, to some extent, the second main issue is how to construct such a compiler.
Regards Zoran
p.s. The reason why I am asking this is that I really had a need for something like this many times.