How to change existing Singletone behavior in C#
I have a problem – we are using assemblies developed by other team (infrastructure team), there is Singletone class we need little bit different behavior. We are thinking of number of possibilities how to deal with code implemented by other development Team.
One possibility is to add additional Instance2 method, but it's not a good idea as we thought. This solution makes our API not usable and hard to understand. May be there is any 开发者_JAVA百科common way to solve it?
If you are using API you don't like simply write a wrapper of this API. Not add method to this API.
You can inherit from singleton for "reuse" or some fine tuning, using templates (C++) or generics (C#.NET).
I've posted in my blog (www.devartplus.com) a serie of posts in this subject:
1) Basic singleton inheritance in C#.NET 2) Thread-safe singleton inheritance in C#.NET 3) Singleton implementations in C++
You are invited to visit those links, and share your opinion. Good luck.
精彩评论