I need to settle this Inheritance problem

Okay, so let’s say I have three classes: Class 1, Class 2, and Class 3.

Now, let’s say:

Class 1:

Class 2:

Class 3

Class 3 inherits from Class 2, which inherits from Class 1.

Should Class 3 be able to access Class 1’s metamethods? Because I have a situation like this in which Class 3 can call Class 2’s metamethods, but not Class 1’s metamethods.

Yes, make sure the function name is different. However I prefer using ECS to avoid inheritance entirely.

local class1 = {}
class1.__index = class1


function class1.new()
	local self = setmetatable({}, class1)
	return self
end


function class1:Destroy()

end

function class1:Class1Special()
	print("Class 1 special")
end

local class2 = {}
class2.__index = class2
setmetatable(class2, class1)

function class2.new()
	local class1Object = class1.new()
	local self = setmetatable(class1Object, class2)
	return self
end


local class3 = {}
class3.__index = class3
setmetatable(class3, class2)


function class3.new()
	local class2Object = class2.new()
	local self = setmetatable(class2Object, class3)
	return self
end


local newClass3 = class3.new()
newClass3:Class1Special()
1 Like

I am assuming Class1 is the super parent, generally speaking only the parent should be able to access lower-level classes, if lower classes require() higher classes then it’s possible to run into a circiular/recursion problem, yes it’s technically possible to have lower classes access higher class methods/information but I would not recommend it. Generally, I create a service that holds methods/information that all modules can retrive