Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@SnafuAI I never use singletons but static classes instead, is that better or worse?
-
SnafuAI6848y@stimulate
Just perfect!
I think I would need a shot or five of Singleton before looking at that codebase :-) -
@stimulate I mean when writing unit tests, you want to mock out your dependencies so that your tests are easier to write and more robust. This is one of the main arguments against singletons. I was wondering if you had a way to do this with your static classes?
-
@linux-colonel
I have honestly not found a way to do this perfectly. I do not have a lot of programming experience yet. I am writing a game engine and because everything basically depends on each other, I find it hard to really decouple the code. I have dependencies all over the place. -
@stimulate
Check out composition, and maybe dependency injection. I don't know c++ so wouldn't be able to help in terms of pointing you at useful frameworks for DI. A game engine sounds like a really cool idea though! -
@linux-colonel
thanks for the information!
But I actually don't think I will need this, because reusability is not that important for a game engine. I think, I have to focus on have a good, fast mergure between my different game systems. I don't know if I am wrong here, and maybe this only applies on a lower level (I am still working on the graphics engine)..
Also I have not really organised my testing yet... -
viking817428y@stimulate do tests.. and maintain them, it will make refactoring later much, much less nerve wracking.
And avoid static classes as much as possible. Better use a dependency injection container and interface dependencies instead of concrete implementations. It's a little mindfuck in the beginning, but when you really understand the benefits you will laugh at your old code
Singelton..... Is it??
undefined