Tag Info

New answers tagged

2

I'd take a step back and ask yourself why you are trying to create a singleton in the first place. Don't get me wrong, I know there's a lot of people hating on singleton, and I think a lot of that hate is unwarranted. That said, it doesn't seem like your singleton is providing any functionality except acting as a global constant to IRCApiImpl. If you had ...


1

Well, as I see it, IRCApiImpl has a public constructor making it difficult to call either way a "classical singleton". Still, I'd say that if you follow the guideline of not creating another instance of IRCApiImpl at any other point or even better, making the class inaccessable, you can use either implementation. From a strict Software-Engineering point of ...


3

FooManager is a smell. Managers invariably suffer problems because a "Manager" is a catchall that pushes it towards having multiple responsibilities. I strongly encourage you to not go down that road towards God objects. Singletons are anti-patterns. Always. They force you to only ever have one object of a type, and no such thing exists. You're going to ...


1

"SRP says methods should do just one thing". True. Constructors should do just one thing, and that is to put the object into a usable state. If just storing the dependencies doesn't put the object into a usable state, then the constructor isn't doing it's job. Did you read anywhere that "constructors with dependency injection should only set the ...


0

"It has some initialization that used to be done in the constructor but it seems that this is generally frowned-on in the DI world" - that's not exactly true. DI is just about providing dependencies externally not creating them within an object. So first thing fo you is to identify, within your singleton, what are it's dependencies and which are other ...


0

Not sure what language you are using, so I'm using pseudo-C# as example. You can create an IInitializes interface, which you then call after the instances are created. public interface IInitializes { void Initialize(); } public class PreviousSingleton : IPreviousSingleton, IInitializes { IDependency dep; public PreviousSingleton(IDependency ...


1

If you're doing logging, it would often be convenient to log the state of any singletons, as they represent global state that might be required to reproduce a crash. If your singleton can be logged by serializing a complete representation of itself, this is ideal as you might also be able to deserialize that state and rerun your program with the singleton in ...


-1

As far as I remember the point of a Singleton is to have only one instance of the class in existence. Serialisation is a transformation of data into another form(at), so that it can be easily written to a file, database or be transmitted, if I recall that correctly. So let's say you have a a class representing some definition (for example, you have a class ...



Top 50 recent answers are included