Dr Darren of Webel IT Australia makes the case for better object-orientation for Mathematica using pseudo class ADTs without losing the super-functional power of the Wolfram Language

Gallery
Tutorial
This is just a cover page intro to the upcoming trail
Dr Darren says:
I've written a lot on this site about the need for proper vendor supported, IDE-friendly, object-orientation for Mathematica, and how that does NOT exclude leveraging the functional power of the Wolfram Language, and how it does not even imply a particular OO paradigm (such as use of state). I'm not going over that again here, please see the many links below. The focus of this trail is specifically on how to use functional-friendly Abstract Data Types (ADTs) as pseudo classes with inheritance."
Click on the image to view it full size
It has NOT yet been decided whether the Webel ADT library for Mathematica can be made public as it may depend on client obligations and commercial restrictions

As one of the biggest fans of graphical Systems Modeling Language v1 (SysML®) for Model-Based Systems Engineering you are likely to ever meet, and given that I am working on integrating Mathematica with SysMLv1 and SysMLv2, I have specific needs. SysML is primarily object-oriented; SysMLv1 uses Blocks, which are UML Classes "on steroids" adapted for use beyond software engineering. SysMLv2 has PartDef and Part instead, which have more flexibility than SysMLv1 Blocks, but are still primarily object-oriented (and not just in the software coding sense).

But even without using Mathematica for my SysML work, there is a need for at least the fine-grained organisational and role-distilling power that Classes offer. I've been using Mathematica for very complex projects (such as modelling air conditioning systems), with SysML modelling in parallel as I go, and it's simply super having that SysML support. For example, I use SysML Activity Diagrams to model and refactor a lot of my Wolfram Language code.

Until recently, I had been using with true gratitude the user-contributed MTools, which, although a valiant effort, does not meet all my needs, including this major issue:

My recent exploration of implementations of what I describe as "pseudo classes" in ADT, and my successful implementation of a form of inheritance, has convinced me that adapted Abstract Data Types (ADTs) are the way to go for my purposes for most of my Mathematica projects in future.

I've introduced some very clear new terminology for the Webel ADT recipe, that will all be explained as we go along in the trail, and is explained in the many linked POLICY note pages.

Before listing some advantages of the Webel ADT approach, please let me make this very clear. ADTs in Mathematica are not to be directly related to the concept of classes you may know from most OO languages! They use Expressions, they attach to the "super functional" capabilities of Wolfram Language, they go far beyond anything that generics (Java) or usual OO templates (such as C++) might offer. Way, way beyond. And they can be generated easily, on-the-fly, transcending many of the issues many of the best known Design Patterns of OO might normally address.

Please note carefully also:

I have decided in part to adopt this approach so that my ADT implementation offers an alternative to MTools, and forces me to think in a more "Mathematica functional" way.

Also, the topic of visibility (package, private, protected, public) is primarily out-of-scope for this trail.

Some good things about the Webel ADTs so far

  • Absolutely brilliantly super suitability to modelling in SysML! You'll see more examples of this as this slide trail is completed. Each ADT-Class maps to a SysMLv1 Block, the ADT-Method UpValues to Operations, the top-level (non ADT) supporting functions map to SysML Activities, and I have a complete set of new SysML Stereotypes with keywords and icons for every concept in the Webel ADT recipe!
  • Thanks to some naming conventions and some context management tricks, a very concise coding recipe, easily accessed also from client packages of the main Webel`ADT`ADT` package.
  • Far better organisational power than just using Paclets and single .m or .wlPackage files. It enables to establish roles, identify responsibilities, and code cleaner.
  • Being able to use ADT pseudo class "strong types" in argument patterns for functions is way, way easier for me than just using regular patterns. Don't leave home without it. And no, you won't lose the power of Wolfram Language patterns, I'll show you exactly how as we go.
  • The Webel ADT coding pattern works really well (not perfectly), in the simply super duper wonderful Wolfram Language Plugin for IntelliJ IDEA, my new great source of joy (and it makes my coding hands happier too). It does not catch the ADT-Class hierarchies, but it's otherwise pretty good, and the IDEA has some cool filtering features, such as sorting by UpValues etc. Refactoring Wolfram Language "variable" names? No issue!
  • I have some terrific new quick help utilities and development utilities that work not just with the ADTs, but with any expression, such as nice UpValues (including ADT-Method) searching, extraction ADT-Methods signatures, and more. Makes Notebooks even more fun.
  • Reuse through inheritance (but by choice, multiple inheritance is restricted to only being allowed in combination with Webel ADT-MemberInterfaces, explained later, and modelled in SysMLv1 using InterfaceBlocks.
  • Use of "passive" ADT-MemberInterfaces (no ADT-Method UpValues) to define membership of ADT-Classes within a role or domain, and if needed at a finer grained level than a Package file. See XL:XL in the image above.
  • Graph inheritance hierachies! Trees of hierarchies! Navigate generated content with clear OO-like structure and "class meaningful" views in interactive Manipulate GUIs.

And all while having my OO cake as I eat my Wolfram functional too! For now, some links to some main POLICY Note pages are listed on the main tutorial page, many of which already have some explanations and code examples:

Dr Darren, Webel IT Australia.
Up next
Notes
Snippets (quotes/extracts)
Visit also
Visit also (backlinks)
Related slides (includes other tutorials)
Related slides (backlinks, includes other tutorials)