Is there any difference /tradeoff between using a static member object and the singleton pattern, I often use the code below in C#, but are there any use cases where the Singleton is preferred?
public class MyStaticObject
{
static MyStaticObject _object =new MyStaticObject();
// OR with static constructor
//static MyStaticObject _object;
//static MyStaticObject()
//{
// _object = new MyStaticObject();
// // additional static construction logic...
// // ...
//}
}
NOTE: this is not the same question as: Difference between static class and singleton pattern?
and other questions which look at static CLASSES. Here my class is not static, just the singleton object. So I have all the benefits of inheritance as listed in the question in the link, but I am not using the singleton pattern for construction.
Aucun commentaire:
Enregistrer un commentaire