Hi, I just wanted to ask a quick question to those who know OOP, it will help me better understand;
How do you name your modules? Like, the type it is/ what it does or its purpose. – What I mean by this is, I see games with modules named like this “[Name of the module]Service”, “[Name of the module]Manager”, “[Name of the module]Util”, and probably some other ones as well. ([Edit]: I just remembered a couple more “Framework” and “MainModule”)
I understand what they mean, but I don’t know where or when to use them, especially “Service” and “Manager”. I researched the differences between both, and they are pretty much the same.
What would you consider a Service, Manager, or Util?
I always use Manager, I associate Service with the built-in Roblox Services.
Also, just to be clear, I think you should only be using either of these things if your Module is actually called every frame/on a loop. Modules that are just configuration or are OOP definitions or just return a single function shouldn’t have either of these. Util I associate more with libraries, such as the built-in table library with a specific focus.
Also, just one quick irrelevant question; How would you use : and . in modules? I can’t seem to find the difference, I have looked at other posts asking this question, but it doesn’t really help, any clue?
The difference between : and . Is that : already contains self while . doesnt. For example,
On an OOP function, you have a constructor
function module.new()
local self = {
Value1 = 0
Value2 = 2
}
return setmetatable(self,module)
end
Assuming you have put a .__index, this constructor returns a self to your server/client, you can access its values or what it have (you can now use class.Value1)
But what if you want to change the values via a function?
This is where : comes in, if you used . You would need to give it a self or the class on the function, however, with : , it automatically gives self
function module:changevalue()
self.Value1 = 3
end
These are also called methods. Class methods more specifically
Also to answer this question based on my opinion, its always best in terms of programing to make your code “modular”, the services are probally a big module script that handles specific stuff (such as chatservice handling chat). This makes it more easier to handle stuff. It probally have many modules under it to make it more readable, while a manager is just a small module script but still something that handles a small thing
I completely agree, I love the idea of modular coding, it’s easy to add new features!
Ahh… Now I see, so take the Players Service, it can be widely used and handles stuff about the players. I should of known that, that makes perfect sense. So I assume Managers would be the same but on a smaller level, and dedicated to one thing, so perhaps a Pet System? – So maybe PetSystem.new() to create a new pet, and PetSystem:NamePet() to name said pet, etc, or would that be a Service?
Right, so as I mentioned before about the Pet System.
Actually, this reminds me; I used to do this, however, it caused a lot of confusion, and just looked ridiculous, so I stopped doing it, but now I’m at the stage where, “What to name then?”.
I now know the difference between most of the conventions, so I’ll apply my new knowledge of this eventually.