# How to implement shared data structures?

If I have a shared data structure like you would find in nested C structs, how would I best implement that in Mathematica?

I have some "object-oriented" code I would like to port to Mathematica. It's not really objected-oriented, except in the sense that there are parent objects and child objects inherit various fields from a common parent. So, for example, there is MovingObject which has velocity, heading, x_position, y_position, etc., and then there are various classes that inherit these common fields. So, you might have a car object, boat object, plane object, etc, all of which extend MovingObject.

The shared methods are non-existent or trivial, so the main thing is just how to share the movement-related data fields.

• In this case, perhaps the most economical way would be to use Association-s with a field called "Type" (or just Type), possibly wrapped in inert symbol(s) if you need to use UpValues and overload some methods, or if you need mutability. Have a look at this example for such a use, for both mutable and immutable case. – Leonid Shifrin May 11 '16 at 17:06