Question

Sometimes I have static types which are really supposed to be static but in rare cases I need to reuse some of their code (couple of methods). I could create an interface or another basic abstract class and solve the problem for several static classes which all really require same methods and members to be overridden but slightly modified. But it still will require me to copy paste large sections of code and I will not be able mark them as static anymore.

Was it helpful?

Solution

You could solve this by building Singleton classes. They can then leverage a base abstract class as well as any necessary inheritance hierarchy, but they still could have static methods that just leverage the private instance if necessary.

Have a look at Jon Skeet's blog on Singleton's so that you build yours properly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top