I’ve been using OOP with projects more and more lately due to how easy it makes managing growing projects, but every time I create a singleton class I find myself asking if there’s really any benefits to using a class structure over a standard module script for singletons, since in most cases they’re being used as managers for the respective objects. Is there something I’m overlooking?
Singleton:
local Singleton = {}
Singleton.__index = Singleton
function Singleton.new()
local self = setmetatable({}, Singleton)
self.Class = "Singleton"
return self
end
function Singleton:PrintHello()
print("Hello")
end
return Singleton.new()
Module:
local Singleton = {}
Singleton.Class = "Singleton"
function Singleton:PrintHello()
print("Hello")
end
return Singleton