OOP Framework check

Am I on the right track or have I completely missed the point of OOP?

--Attempting to make a framework for tweening ui
local TweenTemplate = {
	Part = nil, --Part to be tweened. eg, ui item
	Property = nil, --The property to be tweened. eg, Transparency, Position
	StartValue = nil,
	EndValue = nil,
	Duration = 0.5,--time 
	EasingStyle = Enum.EasingStyle.Linear,
	EasingDirection = Enum.EasingDirection.Out,
	--is this all I need?
}

TweenTemplate.__index = TweenTemplate
local Tween = {}

function Tween.new(part, property, startValue, endValue, duration, easingStyle, easingDirection)
	local self = setmetatable({}, TweenTemplate)
	self.Part =  part
	self.Property = property
	self.StartValue = startValue
	self.EndValue = endValue
	self.Duration = duration
	self.EasingStyle = easingStyle
	self.EasingDirection = easingDirection
	return self
end

function Tween:IncreaseSize(...)--something like this perhaps? or send every property in the template?
	--eg mousehover
end

function Tween:DecreaseSize()--may not be used	
end

function Tween:Rotate()--probably not used (no pets in game, maybe chests)
	--eg pets/chests
end

function Tween:FadeOut()
	--closing inventory screen
end

function Tween:FadeIn()
	--opening inventory screen
end

function Tween:ChangePosition()
	--hiding ui off screen etc
end

function Tween:Creation()--Do I need this?
end


Few minor things:

You don’t need this:

Since you’re already constructing the table here:

You also don’t need this:

Since that’s what your Tween.new does.

Code:

--Attempting to make a framework for tweening ui
local Tween = {}
Tween .__index = Tween

function Tween.new(part, property, startValue, endValue, duration, easingStyle, easingDirection)
	local self = setmetatable({}, Tween)
	self.Part = part
	self.Property = property
	self.StartValue = startValue
	self.EndValue = endValue
	self.Duration = duration
	self.EasingStyle = easingStyle
	self.EasingDirection = easingDirection

	return self
end

function Tween:IncreaseSize(...)--something like this perhaps? or send every property in the template?
	--eg mousehover
end

function Tween:DecreaseSize()--may not be used	
end

function Tween:Rotate()--probably not used (no pets in game, maybe chests)
	--eg pets/chests
end

function Tween:FadeOut()
	--closing inventory screen
end

function Tween:FadeIn()
	--opening inventory screen
end

function Tween:ChangePosition()
	--hiding ui off screen etc
end

return Tween

You also missed some boilerplate like returning the module and setting the .__index, but it looks good so far.

More information if you’re ever stuck: All about Object Oriented Programming

1 Like

Thx for the feedback. I started making my game modular and then though, damn OOP would be better so a week ago I started watching tutorials and reading up it. I made a helper table in case I didn’t pass all the required variables.

1 Like

That’s good. OOP is very powerful in the sense that you can modify whatever you want really easily. If you have any other questions on implementation, feel free to ask.

1 Like