Singleton Pattern [modified]
-
Hi People¡¡ i have a question with Singleton pattern i dont use multithread development and the singleton structure that i use is that
public static GestorBD Instance { get { if (instance == null) instance = new GestorBD(); return instance; } }
but in new GestorBD(), i´d like to pass a parameter how can i do it??becouse i received "0" or "1" i have to read and xml or other xml thanks for all -- modified at 5:50 Tuesday 1st August, 2006Dios creo un equipo perfecto a los demas los lleno de extranjeros
-
Hi People¡¡ i have a question with Singleton pattern i dont use multithread development and the singleton structure that i use is that
public static GestorBD Instance { get { if (instance == null) instance = new GestorBD(); return instance; } }
but in new GestorBD(), i´d like to pass a parameter how can i do it??becouse i received "0" or "1" i have to read and xml or other xml thanks for all -- modified at 5:50 Tuesday 1st August, 2006Dios creo un equipo perfecto a los demas los lleno de extranjeros
Legolas_Bilbao wrote:
but in new GestorBD(), i´d like to pass a parameter how can i do it??becouse i received "0" or "1" i have to read and xml or other xml
If you pass a parameter to the constructor then what you are implicitly saying is that it may not be a singleton. If it is still a valid case for a singleton then create a property or method to take the parameter which will change the existing state of the object.
Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
Hi People¡¡ i have a question with Singleton pattern i dont use multithread development and the singleton structure that i use is that
public static GestorBD Instance { get { if (instance == null) instance = new GestorBD(); return instance; } }
but in new GestorBD(), i´d like to pass a parameter how can i do it??becouse i received "0" or "1" i have to read and xml or other xml thanks for all -- modified at 5:50 Tuesday 1st August, 2006Dios creo un equipo perfecto a los demas los lleno de extranjeros
the one thing that the Singleton pattern ensures as that only one instance of the object exists in your application at any given time. you have a private parameterless constructor that instanciates that object if it doesnt exist (lazy loaded) and thats it. you want to rethink your design if you are having to pass in a parameter to the constructor. Why not have a method inside the GestorBD class called ReadXML(string xmlString)/ReadXML(int method) to do the reading of the xml? Its difficlut to say what is correct without looking at the entire purpose of your class.
-
the one thing that the Singleton pattern ensures as that only one instance of the object exists in your application at any given time. you have a private parameterless constructor that instanciates that object if it doesnt exist (lazy loaded) and thats it. you want to rethink your design if you are having to pass in a parameter to the constructor. Why not have a method inside the GestorBD class called ReadXML(string xmlString)/ReadXML(int method) to do the reading of the xml? Its difficlut to say what is correct without looking at the entire purpose of your class.
thanks i understand it thanks for all -- modified at 13:59 Tuesday 1st August, 2006
Dios creo un equipo perfecto a los demas los lleno de extranjeros