# Mathematica: Webel: ADT pseudo classes: POLICY: The ADT-Methods of an ADT-Class are created as TagSetDelayed UpValues using the 'signature' of the ADT-Class and its defining 'pattern' as 1st argument

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.

In the Webel recipe for pseudo classes with ADTs, an ADT-Method is specified using TagSetDelayed UpValues, an approach adapted from a reply on this forum posting by Mathematica expert Leonid Shiffrin and books on Mathematica by Roman Maeder. As explained by Leonid Shiffrin, the choice of UpValues rather than DownValues (as used by the user-contributed MTools for OO) has some advantages, including being looked up before DownValues.

For example, to directly create an ADT-Method for a class `ADT\$TestString:`:

``ADT\$TestString /: stringLength[pattern] := StringLength[\$\$];``
Note the use of the special `\$\$` for the "wrapped" value slot: We haven't seen yet how the signature pattern is used, but looking ahead, the Webel ADT-Signature here is `ADT\$TestString[\$\$_String]`, so the above ATD-Method can be "invoked" or "called" on an "object" using Webel i:/o: notation for Mathematica input and output cells in online code examples:
``````i: adt\$s1 = ADT\$TestString["string1"]

This of course does not read like the syntax of a regular OO language. An infix operator `⊙` for it can be created as explained under:
``````adt\$s1⊙stringLength
An ADT-Method may take additional arguments, but the signature pattern argument MUST come first. Here a convenient `take` method is defined:
``````ADT\$TestString /: take[pattern,nSpec_] := StringTake[\$\$,nSpec];
``````i: take[adt\$s1, 3]