Tuesday, March 23, 2010

Storing an object to use in multiple classes

Programmer Question

I am wondering the best way to store an object in memory that is used in a lot of classes throughout an application.



Let me set up my problem for you:



We have multiple databases, 1 per customer. We also have a master table and each row is detailed information about the databases such as database name, server IP it's located and a few config settings.



I have an application that loops through those multiple databases and runs some updates on them. The settings I mentioned above are updated each loop iteration into memory. The application then runs through series of processes that include multiple classes using this data. The data never changes during the processes, only during the loop iteration.



The variables are related to a customer, so I have them stored in a customer class. I suppose I could make all of the members shared or should I use a singleton for the customer class? I've never actually used a singleton, only read they are good in this type of situation. Are there better solutions to this type of scenario?



Also, I could have plans for this application to be multithreaded later.



Sorry if this is confusing. If you have questions, let me know and I will answer them.



Thanks for your help.



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails