I'd like to introduce the OOP environment for Mathematica, with no-additional packages.
Mathematica has many style of paradigm, however, OOP is the old but not sufficient backed-up environment for the Mathematica programming. Let's imagine the function group UpSet. UpSet has been seemed the basic idea relating OOP and the function being equipped from the first version but you can see the description of the function group is so small and short in the manual. Now, the UpSet function becomes the most important function because the function group is the key parts to establish OOP environment. With very small size pattern of CLASS constructed with SetDelayed UpSetDelayed, and Module leads us to OOP paradigm. This paradigm includes Encapsulation, inheritance, and Polymorphism in very straight forward manner. OOP on the Mathematica suits for Graphics, Events, and the Dynamic directly and give us new kind of power for Mathematica programming.
Following is a Google slide showing my OOP idea. There is also an attached notebook.
Mathematica OOP is expandable, and following sequence is a combination of OOP and the parallel functions. The method is very easy one as follows.
(*prepare class*)
pclass[nam_] := Module[{local = 0},
set[nam[x_]] ^:= local = x;
get[nam] ^:= (local^2; Pause[0.1]);
]
(*prepare object list*)
AbsoluteTiming[object = Table[Unique[], {10}]];
(*create instances*)
ParallelTable[pclass[object[[i]]], {i, 10}] // AbsoluteTiming;
(*send message to set local values of instances*)
ParallelTable[set[object[[i]][i]], {i, 10}] // AbsoluteTiming;
(*send message to get results of instances*)
ParallelTable[get[object[[i]]], {i, 10}] // AbsoluteTiming
I hope you enjoy the new paradigm.
Hirokazu Kobayashi
Attachments: