I heared something about metatables but my brain isn't available to understand it alone
How does OOP works?
Started by H4X0RZ, May 14 2013 08:39 AM
2 replies to this topic
#1
Posted 14 May 2013 - 08:39 AM
I heared that OOP works in lua, but how does it work?
I heared something about metatables but my brain isn't available to understand it alone
I heared something about metatables but my brain isn't available to understand it alone
#2
Posted 14 May 2013 - 08:43 AM
have a look at http://computercraft.../wiki/Metatable I haven`t used it myself so I can`t give any advie on that, I usually work with regular tables for my OOP-style needs
#3
Posted 14 May 2013 - 08:52 AM
OOP stands for Object Oriented Programming, and metatables are used to give special properties to tables. Metatables and OOP are two completely different subjects. Metatables are used in OOP, however.
The basic concept of OOP is using objects that contain the functions for your program, instead of managing all of the separate variables on your own.
CC already has an example or two of OOP and non-OOP, specifically peripheral functions.
Non-OOP:
OOP:
As you can see here, we use a monitor object as a "middle-man" for calling a function rather than calling the function ourself. In this example, it does take longer, but using OOP does shorten operations in the longrun. Imagine the above examples, but with a couple hundred more writing operations. Using the monitor object would be less typing, no?
The basic concept of OOP is using objects that contain the functions for your program, instead of managing all of the separate variables on your own.
CC already has an example or two of OOP and non-OOP, specifically peripheral functions.
Non-OOP:
peripheral.call('right', 'write', 'Hello World!')
OOP:
monitor = peripheral.wrap('right')
monitor.write('Hello World!')
As you can see here, we use a monitor object as a "middle-man" for calling a function rather than calling the function ourself. In this example, it does take longer, but using OOP does shorten operations in the longrun. Imagine the above examples, but with a couple hundred more writing operations. Using the monitor object would be less typing, no?
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











