The following is an example of using an Association to store information, definitions, routines and even a dynamic display for a mathematical object. A reader can implement and use the routines simply by taking the Values of the Association. This particular example could be improved and generalized but I hope it shows a path toward object oriented type programming. I would consider this useful when you have particular objects with data and routines specialized to that object.
In this case the object is a graph of a function, with two coordinates and a 2-dimensional vector valued result - an embedded manifold in 4-dimensional Euclidean space.
exampleAssociation =
Association[
"Name" -> "Graph Manifold for f",
"Initialize" :>
Clear[x1, x2, \[CapitalGamma], f, \[CurlyPhi], \[CurlyPhi]Inverse],
"Graph Coordinates" -> {x1, x2},
"Graph Domain" -> 0 < x1 < 1 && 0 < x2 < 1,
"Graph Function" :> (f := {x1, x2} \[Function] {x1^2 x2 Sin[x2],
Cos[x2] (1 + x1)^2}),
"Graph" :> (\[CapitalGamma] := {x1, x2, Sequence @@ f[x1, x2]}),
"Graph Chart" :> (\[CurlyPhi][x1_, x2_, _, _] := {x1, x2}),
"Inverse Graph Chart" :> (\[CurlyPhi]Inverse[x1_, x2_] := {x1, x2,
Sequence @@ f[x1, x2]}),
"Active Numerical Report" :> (graphReport :=
Uncompress[
"1:eJzdVNFOwjAUBQElxhgfjL7OP4CRmMibGcGYKCHU8ORLGV1o0rWk3UT+wY/\
2toWNsjmJD5r40t3b23tOz+\
nam5mYRPVaraaOYQgES2Menei8CcMTVQm6hOBB4uXCe8acRoLNvUhIL7JtDRgmYhUdOT1t\
CAYixpT3PdWCZIiZIlUdZxBE3jDlYUIFdNmyxtnOuQ1KZ+9d+/\
HdWqQpDO0LjYmyRZ2OxYrITSc1s5v2bGOIcgcyB8mWBEIVlhjgfBNjlipaz/\
AtV5X688zj136nd9cD/U1ngcVBG95KfWiHE5XoQ+X6vtWCSrWAGwWScn3BAsvE6Atut+\
f7hb4KpAsILIb3yN/gNMk/\
86pwGxvF6rbRKaErbU2n61ujAyHknHKcENXPMdESh0TSDx1ewzAlYQKXeYpZSub59XNp2g\
5N00gD1xsZKKNzsMH06LdjsOY4puHm53flUfjWjEf5/\
CRlRJ1CcL9cEiwxD4lxF8WYscLeW5mnO1wWTGOM0nhG5FDIuJxfB7SRYewA626jbq3V/\
Zh253eAc7CZ0es+WXselO2twn//YP/9P/Z/n/8Q//3f8P+own8zNUoZ+wQ+g1Jj"])];
Some of the entries, such as Name, Graph Coordinates and Graph Domain are simply items of information. But when the Values of the Association are taken other items actually do things. The Initialize item Clears variables associated with the manifold object. Graph Function, Graph, Graph Chart and Inverse Graph Chart establish definitions for the various functions associated for the manifold. The Active Numerical Report. which is stored in compressed form, contains code to generate a dynamic report for the manifold. I developed the code separately, compressed it and then inserted it into the Association.
The Association can be used as follows. First take the Values.
Values[exampleAssociation];
The definitions are now available for use.
f
\[CapitalGamma]
\[CurlyPhi] @@ %
\[CurlyPhi]Inverse @@ %
The dynamic report can be generated by evaluating the following.
graphReport
And you can see the code for the report by evaluating:
graphReport // InputForm