Im crying
I just see people using OOP all the time without chaining inheritance. I think I don’t care if a person chose to use metatables when they need to inherit 25 objects from each other. It’s more about why they chose to do it, but that’s not the point of the post.
I just see people using OOP all the time without chaining inheritance.
I mean, of course, there’s first-level inheritance from the prototype object (“class”) to the object
However, in the context of real OOP, this is not fully inheritance.
The point is that you don’t need metatables in such cases.
People just shove them wherever they want, as long as their function is in the table. It gets to the point where people write methods that no one should see right there, without even realizing that they could write a separate function that accepts self as 1 arg
I think it should be obvious to anyone who has been writing code for at least a year that OOP is nothing more than a wrapper around prototype.method(object)
Why it instead of metatables
- Faster creating for objects
- Faster method using
- Easier to juniors-
- less code
- Easier to make types with this
and a lot more!
So, the concept is based on a singleton. Yes, it’s the same as Roblox services or libraries like string or vector.
Essentially, a singleton is an object that is unique in its kind. Any table that does not duplicate is likely to be a singleton. It does not even require a constructor, simply using {anyKey = anyValue}. Even this is a singleton, and therefore an object, and any table is an object
but what do I mean by library?
A library is a table that is a collection of functions.
But these functions can also include a constructor. vector.create(), buffer.create()
Let me show you.
[https://create.roblox.com/docs/reference/engine/libraries]
local Gun = {
create = function(Damage, MaxAmmo)
return {
Damage = Damage,
Ammo = MaxAmmo,
MaxAmmo = MaxAmmo,
IsReady = true
}
end,
Shoot = function(gun)
if not gun.IsReady then return end
gun.IsReady = false
gun.Ammo -= 1
print("BOOM!")
task.delay(0.5, function()
gun.IsReady = true
end)
end,
}
local gun = Gun.create(10,12)
Gun.Shoot(gun) -- "BOOM!"
Let’s also add types, which is a headache when using setmetatable.
In fact, it doesn’t really matter anymore, as the type is automatically inferred. Regardless, when everything is typed, it becomes much easier to write code.
type gun = {
Damage: number,
Ammo: number,
MaxAmmo: number,
IsReady: boolean
}
type Gun = {
create: (Damage: number, MaxAmmo: number) -> gun,
Shoot: (gun) -> ()
}
and then we add typing:
local Gun: Gun = { ... }Shoot = function(gun: gun)
Even if you don’t like this method, you’ll probably agree that it’s a breeze to use it for GUI animations, as you don’t have to rewrite anything.
In fact, this is very similar to how I do it in C. I find it much less cumbersome than setmetatable
ask questions if anything




