Which is better for efficiency and preformance? Collection Service or OOP (object orientated programming)?
They are almost unrelated concepts. What kind of organization are you trying to create?
These are two completely different subjects/practices of code.
CollectionService
is for keeping objects Organized, and easy to access by code for you to make modifications, which for example:
local part = Instance.new("Part") --create part
part:AddTag("ExampleTag") -- add a tag
for _,v in CollectionService:GetTagged("ExampleTag") do --iterates through all Instances under this tag
v.BrickColor = BrickColor.new("Black") -- changes color of all tagged objects
end
Object Oriented Programming (abbreviated as OOP)is the process of creating classes for specific objects so they can do specific things, for example: I create a class for my weapons, with them each containing data for Animations, Ammo, and Sounds. They also have specific functions to perform this task.
-- data for the class
self.Ammo = 30
self.Reserver = 90
self.MaxAmmo = 31
-- functions for said class
function weapon:Shoot()
self.Ammo -= 1
end
-
If you intend to create classes for a specific group of objects, OOP would be used here
-
If you intend easy accessibility/modification of objects,
CollectionService
is used here. -
Alternatively, you can use a hybrid, where you use
CollectionService
to collect objects so you can use OOP to apply data for them.
Tbh I literally just made a system that uses both
Not correct. For instance, in my poker game, I have to handle multiple tables independently of one another. Rather than using collections, or putting a script in each table, what I do is define a Table class, then I instantiate a Table (which also contains a reference to its corresponding table model) for each poker table in the folder. This allows all the tables to be easily managed from a single controller, which is a more powerful version of a collection.
So, OOP is more powerful if used in the right way. CollectionService might have the advantage of being quicker to implement for small use cases, but I am not convinced of its usefulness at all.
Yeah you can do the same things with it I feel. But collection service is more intuitive I think. But. It gets messy quick… Still. I think using collectionservice is just easier… I say this because dont you still need to put a script in every unit (player or table or npc) to tell a ‘table’ to do a thing if idk e.g. a certain player sits down? If you want that in a single script you’d still be looking at a loop or collectionservice… I puzzle over this
And couldn’t you give your ‘table’ certain values by using the attributes or properties systems? Nobody seems to use that…Is something wrong with it or something? I guess it’s not really necessary if you’re good with your own tables? And you can give em certain functions by using collectionservice, coroutines and plenty of if statements?
Still, classes through metatables are neat. But like I said, wouldn’t you have to trigger its functions in a separate script anyway… And if you wanna do that for lots of the same type you’d still be using a single server script with collectionservice? Idk