I've been stumbling in some of my more bigger projects into a big problem.
I use OOP to keep my code sorted and come across no big deal on smaller classes I am creating.
What comes off as a big problem though is keeping the functionality of the old function I want to override.
Whenever I implement an abstract function to try to keep the old function's properties, problems stack up even more,
as my brain can't simply comprehend anymore which function to use and name.
In summary with the following example:
Is there a way to call for 'function Dimension:update(dt)' without 'Pointer:update(dt)' losing its functionality?
Code: Select all
-- Class Pointer --
function conNewPointer()
local Pointer = {}
-- Variables --
Pointer.x = 0
Pointer.y = 0
function Pointer:update(dt)
-- Original update --
self.x = self.x + 1
-- Compensating for not being able to keep old properties --
self:abstractUpdate(dt)
end
-- Too complex abstract function to try to compensate. --
function Pointer:abstractUpdate(dt)
end
return Pointer
end
-- Class Dimension --
function conNewDimension()
local Dimension = conNewPointer()
-- Using this function to compensate for not being able to keep old commands of previous function,
-- when calling Dimension:update(dt) --
function Dimension:abstractUpdate(dt)
-- Inconvinient solution. --
self.y = self.y + 1
end
return Dimension
end