Hello ! This is my first post on the forums. I have gone deep into a rabbit hole trying to wrap my head around the Single Script Architecture framework. I have a some background in Java, so I understand the concepts of OOP. I have possibly read every article relating to OOP and the single script architecture in this forum and still can’t grasp certain aspects so I hope someone can point me in the right direction.
Please go easy on me if some of the questions may be straight forward or easy.
For Example… some frameworks I have come across have folders in ReplicatedStorage for:
Services
Data
Classes
1. What is a Service ? What differentiates an Object from a Service ?
I understand that a Service has persistent state, so does that mean they are all singletons? How are they different from Classes (or objects )?
2.How do you differentiate your Module Scripts ? How do you decide what will go into Data, what will go into Classes, etc…
3.Is Lazy Loading a form of dependency injection ? If not , what are the ways to decouple dependencies?
4. Are there any ways to unit test code ?
Any resources that you can point me to will be greatly appreciated !
Please if any software engineer geniuses are reading this I need your guidance !
Thank you for reading
First and foremost, this is Lua and singleton means just about nothing here. A service is an Instance object that Roblox has designated as a service, always as a descendant of Game. Workspace, Players, Lighting, ServerScriptService, HttpService, StarterGui, Teams, these are all services. You can find a list if you look. They are all singletons in the sense that you can’t have two of them, though they are implemented in C and I am not sure how they are handled behind the scenes. I would imagine that as inheritors of the Instance class, they are handled the same as every other Instance. An Instance, if you didn’t know, is the type of Object that shows up in the explorer view. Parts, GUIs, particle effects, Scripts, etc.
ModuleScript usage is completely up to you, Roblox doesn’t have much in the way of recommended structuring. Most people only use ModuleScripts as utility libraries.
I’ve used C# quite a bit but I’m self-taught and don’t know proper terminology. I know what lazy loading is but I’m not sure what the rest of the question here is asking.
Unit testing can be either easy or difficult depending on what platforms you usually develop on. Most cases on Roblox it is very easy to take snippets and adapt them for unit testing. You can’t really unit test in place though. But it’s straightforward enough that I regularly do it with people’s questions on the dev forum to make sure my answer works.
After further research, I’ve found a lot of answers to my questions on the AeroGameFramework page. To anyone in the future with similar questions, I recommend reading through each section in the AeroGameFramework.
Modules can be separated on their intended use case. So data would be data objects(modules that contain data like constants), services would be singletons(only created once), objects would be modules that can be instantiated (have their own properties and methods)
Also to clarify, Lazy Loading and Dependency injection are totally different.
Lazy loading is the practice of loading a piece of code only when it is needed, while dependency injection is a method of decoupling objects and classes (as per the dependency inversion principle).
If a module is lazily loaded, that does not change if its tightly coupled.