Tag Info

New answers tagged

4

I have chosen a singleton pattern because: I want the singleton to hold nested classes; one class for each pattern. This doesn't require a singleton, or a static class. You could have public class Patterns // non-static { public class PatternA : IPattern { } public class PatternB : IPattern { } } and you'd be able to use it as a ...


1

Your modified approach to singleton is still a singleton, and has most of the drawbacks of a singleton: It still introduces high coupling across the application - that is, if one day you want to refactor away from singleton, you will have a hard time doing it; It still gives a way for any component to collaborate with the singleton - meaning that ...


3

Static data (including singleton instances) is problematic for a number of reasons. It's not thread-friendly. You have added a method to set the single instance to a mock instance. Presumably that is done to support unit testing. This will fail if tests are run in parallel and require different mocks for your Singleton. Worse, the tests will fail when ...


2

The reason I give dependencies to constructors is: Most of the time the dependencies are required, so why not give them to the constructor Giving them to the object in an other way makes using them a bit more complex, since you have to make sure you have the dependency Of course this doesn't really count when you are using a framework that controls the ...



Top 50 recent answers are included