Mathematica: MTools: Argument pattern matching does not respect inheritance (undermines design-by-contract and heaps of Design Patterns)

This page identifies a possible issue, concern, error, limitation, or bug!
Webel IT Australia promotes the amazing Mathematica tool and the powerful Wolfram Language and offers professional Mathematica services for computational computing and data analysis. Our Mathematica tips, issue tracking, and wishlist is offered here most constructively to help improve the tool and language and support the Mathematica user community.
DISCLAIMER: Wolfram Research does not officially endorse analysis by Webel IT Australia.
Icon class
icon_class
far fa-sticky-note
icon_class_computed
far fa-sticky-note
Note kind
Policy level
Keywords
Argument pattern matching works against a single MTools class name, there is no consideration of inheritance. Consider this setup with MClassB extends MClassA:


BeginPackage["Demo`", {"MTools`"}]

$ContextAliases["M`"] = "MTools`Core`MPlusPlus`";

MClassA = M`NewClass[{"Fields"->{"name"}}]

MClassB = M`NewClass[{"Parents"->{MClassA}}]

newB::usage = "newRefR32[name]";

Begin["`Private`"]  

newB[name_] := M`New[MClassB]["name"->name];

End[] 

EndPackage[]

This works as expected (matches against a specific class):


i: b1 = newB["b1"];

i: fTestB[b_MClassB] := M`o.name;

i: fTestB[b1]

o: b1 

But matching against the parent (base) class does not work:


i: fTestA[b_MClassA] := M`o.name;

i: fTestA[b1]

o: fTestA[MClassB[object$123435]]


NEW: The Webel recipe for pseudo classes with adapted Abstract Data Types (ADTs) handles design-by-contract fine:
Relates to
Related notes
Related notes (backlinks)
Related snippets (extracts)
Visit also
Visit also (backlinks)