29
dror
7y

Singelton..... Is it??

Comments
  • 1
    High Singleton usage is a sign of a bad architecture😁
  • 1
    @SnafuAI I never use singletons but static classes instead, is that better or worse?
  • 0
    @stimulate
    Just perfect!
    I think I would need a shot or five of Singleton before looking at that codebase :-)
  • 0
    @SnafuAI
    Nice :)
    Static classes are even so much easier to implement
  • 0
    @stimulate how do you mock out your static classes for testing?
  • 0
    @linux-colonel I don't know what you mean.
  • 0
    @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?
  • 0
    @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.
  • 1
    @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!
  • 0
    @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...
  • 3
    @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
  • 0
    Is Codeigniter singleton?
Add Comment