I know that Singleton
guarantees me a single instance of a given object. I got this. What creates me doubt would be its use in practice like that. Let's assume the code below, using Singleton
with Generics
(code taken from the internet).
public sealed class Singleton<T> where T : class, new()
{
private static T instance;
public static T Instance()
{
lock (typeof(T))
if (instance == null) instance = new T();
return instance;
}
}
I have an order form where I will post my orders. Will I instantiate my Pedidos(T)
class? And the connection to the bank, how do I do it? That is the question I have when implementing this Pattern. Where does the connection to the bank come in?