Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Roman Maeder's object oriented programming package is nice, but I'm hoping someone can suggest a sleek and novel implementation that is easy to use.

share|improve this question
Can you tell us more about what functionality of OOP you'd most like to implement in Mathematica? – Jagra Jun 6 '12 at 17:47
Similar: – Sjoerd C. de Vries Jun 6 '12 at 18:02
OO is a moving target, as is nicely summarized here, so you first need to define which set of features you call OO (as noted already by @Jagra). Implementing some basic OO by itself is not very difficult, but you will face some pretty hard to solve problems, such as performance and garbage collection. In this answer, I dwell a little more on this topic and link to some previous discussions on the matter, which you may find of some interest. – Leonid Shifrin Jun 6 '12 at 19:38
Some interesting discussions in this topic can be found on MathGroup. Here is a recent one. – Jens Jun 6 '12 at 22:16
up vote 5 down vote accepted

Well, one obvious idea would be to build on the struct implementation by Bob Beretta. You would have to add information about methods and modify the implementation of --> to consider those as well, and for polymorphism, you'd also have to store the base class (or base classes, if multiple inheritance should be supported), and have --> look there if the field or method is not found.

share|improve this answer

[...] but I'm hoping someone can suggest a sleek and novel implementation that is easy to use.

The answer to this is to use Object-Oriented Design Patterns in Mathematica as explained and exemplified in the presentation "Object Oriented Design Patterns" at the Wolfram Technology Conference 2015. (The presentation recording is also uploaded at YouTube.)

Here is a link to a document describing how to implement OOP Design Patterns in Mathematica:

"Implementation of Object-Oriented Programming Design Patterns in Mathematica"

The described approach does not require the use of preliminary implementations, packages, or extra code.

Design Patterns brought OOP into maturity. Design Patterns help overcome limitations of programming languages, give higher level abstractions for program design, and provide design transformation guidance. Because of this it is much better to emulate OOP in Mathematica through Design Patterns than through emulation of OOP objects. (The latter is done in all other approaches and projects I have seen.)

Related posts/descriptions/answers

  1. Blog post "Object-Oriented Design Patterns in Mathematica".

  2. Blog post "UML diagrams creation and generation".

  3. This answer in the discussion General strategies to write big code in Mathematica?.

  4. This answer in the discussion Can one identify the design patterns of Mathematica?.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.