lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Am 27.02.2014 13:33 schröbte Wouter Scherphof:
The below snippet from Luvit might be pretty much all OO you ever really

This is also my opinion, irrespective of the actual OO snippet given! OO programming in different languages consists of a bunch of optional (and mostly independent) features. The only required feature (IMHO) is the polymorphism/late binding/virtual function thing, which allows old code to call new code (in contrast to procedural code where new (user) code would always call old (library) code). Pretty much all Lua OO modules get this one right by looking up methods in the objects.

For everything else you need to decide which OO features you want (and why), and whether the costs in runtime and memory are worth it (a statically compiled language can pay some of it at compile time, with Lua it's all at runtime).

If you want to reimplement the GoF patterns in Lua you probably need most of the OO features that C++ provides. I don't know how reasonable that is. But even if you find or write the perfect OO module for implementing GoF patterns, you might need a different OO feature set for your next project ...

I guess that's why pretty much everyone writes his/her own OO module at least once (I've done three so far).