OOP
Ahh yes, the programming paradigm of object oriented programming.
the paradigm of OOP is defined as:
is a programming paradigm based on the concept of "objects", which can contain data, in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods).
by wikipedia
it can be thought of similar to real life objects, which have properties and functions(methods)
for example
class lamp
boolean state
method turnOn()
method turnOff()
would be psuedocode for a potential lamp class that can model a real life lamp, which can be on or off, represented by the state property. The act of turning the lamp on and off can be represented by the turnOn and turnOff methods
Key terms associated with OOP includes
- Inheritance
- Encapsulation
- Polymorphism
these i highly recommend you research in order to properly understand OOP
A positive of OOP it that it provides is a way to remove the assumptions of the condition of components; thus, the operations to be performed on that component and how to integrate it into the final product. (stackexchange)
Other positives of OOP can be found on the stackexchange post
OOP vs Procedural
(im assuming thats what you meant by "regular tables and such")
If you want to compare different programming paradigms, this page could be helpful in doing that,however, i want to list a few key differences
One of the more obvious ones is nomenclature , for example:
| Procedural |
OO |
| Procedure |
Method |
| Module |
Class |
One key difference is re-usability, as designs in OOP can be reused, however, the same cannot be said for procedural programs.
Anonymous functions
In computer programming, an anonymous function is a function definition that is not bound to an identifier. Or more simply, a function without a name
They are typically used as arguments which are passed to higher order functions.
examples of this in (roblox) lua include common format for event listeners
event:Connect(function(...)
end)
the function in there is an example of an anonymous function passed as an argument to the connect function, which connects the event to that function (hence the name connect).
self
putting it simply, self is just a variable name. According to the lua pil,
First, the function creates a table to keep the internal object state and stores it in the local variable self.
when refering to an "object constructor"
it is simply a variable name that is implicit to whatever table/userdata the value was called from with a colon (if that makes any sense)
like Object:Destroy(), or event:Connect()
Methods vs Functions
they both refer to a set of instructions that performs a task, the difference being that Methods are associated with an object, while functions are not.
This is getting a bit long-winded so ill try to keep this bit as short as possible. As you may or may not think is obvious, OOP isnt ubiquitous. One drawback is the difficulty of planning an OO program, as the flow isnt obvious when it comes to OO programs, thus increasing the time necessary and difficulty to write an OO program.
also if i stooged something up, be sure to tell me
2 comments
several OOP jokes were killed during the making of this answer
@theking48989987 could you show some examples of OOP and how it can be used?