Thread: ZO_Object
View Single Post
07/06/15, 10:30 AM   #8
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by Atropos View Post
Thanks to those who replied, but I'm still not clear what the actual gain is from trying to force OOP like this. Can someone provide an example use case where using ZO_Object allows them to do something that would otherwise be a big pain in the ass?

Is it simply a mechanism for making programming LUA more friendly/intuitive for people who are used to other OO languages?
Think of it as convenient syntax sugar.

Compare:
Lua Code:
  1. local Bar = {}
  2. function Bar:foo() ... end
  3.  
  4. local b = setmetatable({}, {__index = Bar})
  5. b:foo()

To:
Lua Code:
  1. local Bar = ZO_Object:Subclass()
  2. function Bar:foo() ... end
  3.  
  4. local b = Bar:New()
  5. b:foo()

It simply adds descriptive names to Lua constructs. You can see right where Bar is defined that it's a new (sub)class. And that b is an instance of Bar.
  Reply With Quote