OOP extends past the scopes of Roblox and is one of the most common paradigms (way of programming) in software worldwide. Standing for Object Oriented Programming, OOP breaks down the main control script of a program into the highest level of abstraction possible through classes and objects, meaning there is very little code and more so functions (or methods) which handle the execution and function of certain modules. As you delve into these modules, you go through lower levels of abstraction, until you get to the lowest level of abstraction, which holds all the code.
This is a bit confusing, and doesn’t really have much application unless you can understand what it means, so I’ll start by teaching you some concepts of Object Oriented Programming. The main idea of this paradigm stems from the idea of Classes and Objects.
Imagine you have a car factory, and you want this factory to produce some red cars. The car factory would be known as the class, and this stores all the information needed to create a car, which is the object. When you create a car in a factory, you must consider how big it’ll be, what it can do, etc. So whenever we tell our car factory to produce a car, which is also known as a “constructor” function, our car will come out identical to all other cars produced from this factory. In addition to this, it will have all of the functions (also known as methods) which we can use on our car, such as :Drive()
or :Park()
.
Now we know about our factories (classes) and cars (objects), we can talk about inheritance. Knowing how to make a type of car is all good, but what if our car factory wanted the ability to produce a new type of car which can fly? Instead of making an entirely new factory, which does the exact same thing with this new feature, we can create something which is known as a “sub-class”. This concept uses the constructor of it’s super class (the factory above it) to produce an object, like our car, and then the sub class applies it’s own changes, as shown in the image below.
Objects within our OOP paradigm have all their data held together within them, so we do not need to store it across multiple variables. As such, when we want to access data which is “encapsulated”, we would need to access one of it’s attributes. You do this all the time without realising it! For example, when you do Part.Name
, you are inadvertently fetching the name from the object identified as Part. In addition to this, our objects have functions which can act upon themselves, which are known as “methods”.
The concepts I talked about here are just a few of the many, many intricate details of OOP, however these are just the basics to get you started. All though Lua may be unconventional in the way we apply the paradigm, it very well exists in the same way and is still used by most programmers within the platform.