Association and rudimentary object-oriented programming

Doesn't Association provide us rudimentary object oriented programming via constructs like

TEST = Association["value" -> 2, "method" -> Function[{x}, x^2]]
<|"value" -> 2, "method" -> Function[{x}, x^2]|>
TEST["value"] = TEST["method"][TEST["value"]];
TEST
<|"value" -> 4, "method" -> Function[{x}, x^2]|>

Do any of you familiar with Mathematica syntax and details see ways to extend this theme to include inheritance and other features of OO?

Is anyone attending the Wolfram conference next week who would like to discuss?

• I have discussed this topic a bit in my post on the use of Associations, and also here (not in the context of Associations). I you search this site, and also Wolfram Mathematica tag on Stack Overflow, you will find many more OO-related discussions. – Leonid Shifrin Oct 17 '14 at 14:09
• OO-programming was one of the things the very first books on Mathematica tackled, and then it became forgotten somehow. The Mathematica Programmer (Maeder, 1994) devotes a chapter to OO-programming in Mathematica, and so does Mastering Mathematica (Gray, 1996). Association on the other hand is new since of this summer, it is approximately twenty years younger than those books... – C. E. Jan 16 '15 at 1:25

Associations (also knows as dictionaries) are essentially all that is needed for a crude class system (real men use structs, of course), and this is quite explicit in Python. However, using JUST dictionaries (or associations) without any syntactic sugar will produce extremely ugly (not to mention slow, but sugar won't help the latter problem) code.

You could already do this with DownValues

TEST["value"] = 2;
TEST["method"] = Function[{x}, x^2];
Definition[TEST]

TEST[method] = Function[{x}, x^2]

TEST[value] = 2

TEST["value"] = TEST["method"][TEST["value"]];
Definition[TEST]

TEST[method] = Function[{x}, x^2]

TEST[value] = 4

This method might be easier and more straightforward.