Message Boards Message Boards

OOP environment for Mathematica without additional packages

GROUPS:

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:
POSTED BY: Hirokazu Kobayashi
Answer
11 months ago

You can add something in the general topic on SE or in topics linked there:

Which Object-oriented paradigm approach to use in Mathematica?

enter image description here

POSTED BY: Kuba Podkalicki
Answer
11 months ago

This mind map is asking to reconsider on the Mathematica OOP, "how to" develop or/to "why to" develop it. Though, if we can achieve OOP with very small cost, the importance of "why" becomes lower one. My idea for the OOP requires very small cost, it means a few lines code is additional, so "why" will have small meaning in my OOP case. On the contrary, we can obtain large advantage from the OOP.

The power of Mathematica comes from many characteristic points, and I think the various programming paradigm may be the largest one, so OOP will become the new large power source.

POSTED BY: Hirokazu Kobayashi
Answer
11 months ago

It would be great I think if you would be able to explain your OOP idea in-post here or attache a notebook.

POSTED BY: Sam Carrettie
Answer
11 months ago

Yes, I attached a notebook.

POSTED BY: Hirokazu Kobayashi
Answer
11 months ago

Hi,

Apologies, yet I do not see how your approach promotes re-use, abstraction, encapsulation, or Typing of any sort. Despite your mention of design patterns, I do not see how it can, for example, be used to implement common patterns such as observer, visitor, or, most ubiquitously, singleton. Most importantly, I unclear how it helps me, in structuring code this way, reduce complexity or improve understanding.

I did download your notebook. Unfortunately, this was not enough to actually understand what it is that you are proposing and what advantages there are in contrast to other approaches. I think much might be understandable were there a more in-depth write-up similar to that others have posted when putting forth their proposals for approaching OO in Mathematica.

Regards, Dave

POSTED BY: David Fuller
Answer
9 months ago

One more Q: Why would I 'construct' a superclass specifically that I might 'subclass' it? That does not appear to make sense. I am assuming that your example is just unclear in some respect.

POSTED BY: David Fuller
Answer
9 months ago

So you are asking why is a superclass necessary in general? Briefly, it is related to the design pattern and to make the design looks clear and logical.

POSTED BY: Shujie CHEN
Answer
9 months ago

No, I'm not asking in general. I well understand the purpose which is why I asked the questions I did.

I'm asking why, apparently something must be declared to be a superclass using a super function? Is that not the point of stating that the child generalizes the parent?

This is why I'm asking for some more exposition regarding this approach. If it, somehow, provides the benefits of OO simply by convention then it is indeed well worth understanding how exactly it does this and what positive and negative effects may accrue.

POSTED BY: David Fuller
Answer
9 months ago

OOP, Object Oriented Paradigm may not be familiar as a tool for Mathematica programming, so, I'd like to introduce some examples using OOP, considering this six months discussion after the publish of my idea.

POSTED BY: Hirokazu Kobayashi
Answer
6 months ago

Group Abstract Group Abstract