OOP (Object Oriented Programming) - Lua tutorial (Part 15)

preview_player
Показать описание
OOP, or Object Oriented Programming is one of the most popular ways of programming. Whilst Lua is not an OO language, it can still simulate objects using tables (and in this case, functions)

Group Chats:

You can contact me on:

Any suggestions? Leave it in the comment section or contact me somewhere else!

Thank you for watching!

#stevesteacher #lua #learnlua #learntocode #code #programming
Рекомендации по теме
Комментарии
Автор

Finally this makes sense! I have read and watched so many OOP Lua programming tutorials for LOVE2D specifically and I never really "got" it until now.

erinlane
Автор

man this is very nice, i always like the "factory functions" design pattern you used to make up for absence of classes.

liarleyev
Автор

12:38 Unless I'm sorely mistaken (I'm coming from a bunch of other languages here) that is not inheritance at all. What you are doing there (in an OOP way of thinking) is instantiating a locally scoped object of the Pet class. Not really anything new or special. Your Dog class is not inheriting from your Pet class, ie, you could not use Dog.status directly as it is written. (unless I'm sorely mistaken which would be surprising to me)

AkamiChannel
Автор

I followed your tutorial, and decided your pet should be fed only once, or you'll overfeed him. I added extra lines of code

dog.feed = function(self)
if self.status == "Hungry" then
print(name .. " is now full")
self.status = "Full"
self.loyalty = self.loyalty + 5
else print(name .. " has already been fed")
end
end

and added an extra function that lets you train him.

dog.train = function(self)
print(name .. " has been trained")
self.loyalty = self.loyalty + 5
end

I feel accomplished

KuraakaiGoro
Автор

Cat "Luis" is always hungry by default and you cant change his status.

vilser
Автор

So Lua is like Flutter & Dart Object Oriented Program?

malakash
Автор

i understand the subclass of OOP and how you dont need to have say, 50 objects that need the same default thing but just 50 subclasses to save space and the like. i just dont understand HOW to make it. functions and tables and the like confuse the hell out of me.

dankmemes
Автор

Procedural programming is not functional programming. Aren't procedural and imperative programming the same?

AkamiChannel
visit shbcf.ru