4 ms·
Whatever it takes to emulate object-oriented programming in languages without objects and classes. Creating structs as objects and passing them as first argumen
by jonathanstrange 3y ago
Whatever it takes to emulate object-oriented programming in languages without objects and classes. Creating structs as objects and passing them as first arguments. But I also meant it to include using closures, function pointers, and type-switches to emulate dynamic dispatch, creating inheritance hierarchies by embedding higher classed object into structs in whatever way your language supports. Sometimes people also resort to code generation. Even explicit dynamic dispatch may be implemented, e.g. by storing class hierarchies explicitly.
The hallmark of it is that "objects" are passed as first arguments to functions in languages that don't support syntactic sugar for methods.