Classes

in http://code.google.c…ets/Classes.lua taktik has created an example (it’s also included in the Xrnx Starter pack, in the folder “Snippets”, the file name is “Classes.lua”)

i’ll place this thread out as a placeholder for future dissection of classes

specifically i want to tie concepts like “constructors” and such to the discussion and find out how they apply to the above classes.lua example

this is a challenge for me, and i’ll research the official lua docs and other sources until i get a good grip of this… stay tuned…

ok, my first impression of classes:

it seems to me that the main point of classes is to save time/effort, amount of code lines, and possibly also cpu power

kind of like we don’t say “let’s go to the zoo and watch the… elephant, lion, monkey… phew, well all those things that we can watch”

but rather we say “let’s go to the zoo and watch the animals”

so… basically a class seems to be a group of objects that share a common set of attributes and behaviors

this classes-example is actually one of the examples in the lua snippets i found pretty clear. but it is always difficult to explain completely in simple, non-technical terms.

the way is see it, these classes are like group-names. so, in the example in Classes.lua, you got the ‘Animal’ class, with derivative classes ‘Mammal’, ‘Bird’ and ‘Fish’.
but, as shown in the example, you need to define the ‘constructor’ for the class, which means you need to define the arguments which the function attached to the class needs (for definition of these terms, see the Glossary! :)…

now my question is: what does _init do exactly?

maybe __init is basically like a command to poop a new instance object that derive from the class

like in LOTR, when Sauruman creates the class “orchs” and then __init them out of the mud :)

init = initialize?

maybe the __init marker also is necessary if we want to attach specific instructions on what to do upon initialization

like if we stand in front of a copy machine and press the button “copy”

the init could then be like “if somebody presses the copy button, then blow up the building”

yeah i’m pretty sure init == initialize (if we’re gonna talk programming, better use the right syntax too, so ‘==’ means ‘is equal to’, while ‘init’ = ‘initialize’ changes ‘init’ to ‘initialize’ :), and i can go along in your Saruman analogy :smiley: - in fact, if this turns out to be true, remind me to use that analogy in the Glossary! might as well have some fun while we’re at this.

keep it connected!