Solved

Is it OK to store data globally?

Posted on 2004-04-08
7
164 Views
Last Modified: 2010-05-02
I have a VB6 (SQL 2000) app that has a lot of "preferences" that need to be available througout the use of the program.

What I have now is a preferences class that is created and filled when it is needed - then destroyed.

This is called alot throughout normal use.  

What is an acceptable way to store these values for the life of the app?  I would like to cut out some database traffic and only get these values if they have changed.  The values are only related to the running instance of the app so I dont need to worry about other users changing values.

I was considering using a global instance of the prefernces class? Is this bad practice?
0
Comment
Question by:tmorita
7 Comments
 
LVL 18

Expert Comment

by:Sethi
ID: 10788704
No it wont be a bad practice. Infact it would be a better practice as it will reduce the time to create and destroy the class.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 10788948
What do you mean by "a global instance of the preference class"?
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10789179
>> I was considering using a global instance of the prefernces class? Is this bad practice?

Siskel and Ebert give it two thumbs up. :]

It's fine to use a Class Module to encapsulate settings IMO. If you do decide to, declare your variables as private and use property subs to Get/Let. This'll keep the variables out of the object's interface and allow you to update the private variables within the Get/Let sub before returning their values. Because of this, you can avoid exposing additional properties/methods to the object's interface when you just need to get updated values.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 27

Expert Comment

by:Dabas
ID: 10793951
Hi tmorita:
I would add a .bas module to your program with Global variables.
I agree with Sethi, it is not bad practice

Dabas
0
 

Author Comment

by:tmorita
ID: 10794927

>>What do you mean by "a global instance of the preference class"?

I already have a class with private variables.  The way it works now I declare/create/use/destroy this class all over the program to access these preferences.

I could create this class globally - once when the program opens - and use it thoughout the program.  

Instead of creating a module with global variables. (same thing really?)
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10794945
tmorita:
> same thing really
Nearly. Yes
I have used both ways. It depends on if and how you want to reuse the class/module

Your original question is:
Is it OK to store data globally?
Answer is Yes.

Dabas
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 200 total points
ID: 10795027
>> I already have a class with private variables.  The way it works now I declare/create/use/destroy this class all over the program to access these preferences.

You might as well keep the class the entire duration of your app since destroying it constantly isn't any better. If there's anything within the class that uses a lot of resources, you can place that in a seperate class and destroy it or destroy it within the current one. If there isn't, there's not much reason to support desroying it.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now