Looking to get into using Maids in my games now and I was curious if people could share some best practices or guides on use cases beyond the basic explanation on what Maids are.
For example, I might have numerous services(on the server) in my game and i want to mange bits of data during the play session related to players and clean those up when they leave.
Right now, what I do is connect the setups to PlayerdAdded and then i manually cleanup stuff when the PlayerRemoving event fires, making sure in each service to clean up whatever I did with the player.
Should each service create its own maid? Should i have one central place where there just one maid for the player and everything goes into that one? What do other people do?
I hear people raving about Maids and I want to get exactly why, because so far its not that hard to just remove player related data when the player leaves.
I don’t have maids in my systems because I don’t think they’re needed.
Instead, I have a single function, normally along the lines of :cleanUp which will remove the current instances and such used within the service.
it comes down to; are you adding stuff to help the game, or to add to the game.
the way you have it right now i’d see as normal or ideal, but I dont really understand the entire point of a maid, why create a new reference to an object, when you can clean it yourself…?
Either way, yeah, Each have their own way on coding
Basic explanations of the Maid pattern also double as best practices and use case examples, so really the answer is in the explanation of what it is and what it’s used for (lit. the use case). By reading the explanation you already have an answer to your question.
I use them for virtually anything and even sometimes when I’m just too lazy to do object management myself and would rather pass them off to a Maid:
Cleanup of cutscene resources. Disconnect connections, stop animations, reset game state.
Working with Roblox characters is the most frustrating, painful, limiting, awful experience I’ve had the displeasure of needing to be concerned with. I link a Maid up to a character and anything that should work for that specific character is managed by the Janitor. Character gone, so is everything else that needs to operate on it, then I start anew with the new character.
For classes and frameworks, I might have service-level and object-level maids that handle their respective environments. For example, a service-level maid might clean up an object-level maid. I can’t think of an exact detailed scenario off the top of my head where I’ve done this but I know it’s a hypothetical use case I might encounter.
There is a such thing as abusing the pattern though. A data layer doesn’t necessarily need a Maid involved. You can hand-manage your connections and caches. You most likely aren’t going to have instances as a dependency for data and if you do that’s slightly terrifying.
For some reason it seems the link to your profile is broken.
Personally I don’t use maids because simply put, I don’t need them. The only thing I have remotely close to a maid is when I make custom character controllers with keybinds I usually have an Controller:Init() to bind the actions and connect the event and then I have a Controller:Term() function which basically disconnects and resets everything back to how it was so the player can respawn again fresh as new.