All about Object Oriented Programming

Can’t believe this tutorial is almost a decade old and still holds up this well. Excellent job!

I discovered this thread a while back but come back to it now and again to remind myself/correct myself on what I’m doing but this thread has been incredibly helpful in metatables and I’ve even implemented it into my projects. Great resource :slight_smile:

Very nice tutorial!

I’ve actually written a module that I might open-source later that actually makes implementing OOP very easy including inheritance.

Calling module:class(your_table_here) automatically assigns it a :new() function for making instances and a :init() function that gets called every time you make a new object for setting initial values.

All these functions can be overwritten if desired.
Calling module:class(table1, table2) for instance will turn table1 into a class that inherits from table2.

Using bindable events, other scripts can communicate with classes without having to require() them or know of their existence, should all be relatively memory safe too.

Your tutorial is nice and I hope more people will utilize OOP, it’s unfortunate Lua doesn’t just have classes like C++, C# and Java.

Using metatables still feels a bit hacky an unofficial.
They’re also slower and less efficient than native OOP implementations.
Unfortunately tables use more memory than objects. :frowning:

Hello there, I’m new to OOP so I have a question. Does Car.new() actually create a new car ? If so then how do you define what Class it is?

Great tutorial, very clear and concise, however I would go over metatables for new people more in depth, as it’s a essential aspect of replicating oop within luau

it’s just a function that puts its arguments inside of the self value.

love the idea! sounds simple to make though.

I had trouble seeing the point in OOP, then I read this and it all makes sense lol.

This tutorial is truly amazing! I can’t thank you enough for it :smiley:

This was made in 2014, however, it’s still very useful.

I’ve been doing this already in a different way! OOP is much more convenient though.

local Car = {

["Speed"] = 100
["Size"] = Vector3.new()
}

amazing way of explaining it thank you so much man!

2024 and still helpfull :stuck_out_tongue: tysm!!!