Original Post
🔒 Locked
Static class as global variable
Advertisement
Yeah that''s a fine idea. Conceptually, a public static thing is a global, cause it is accessable anywhere and there is only one of it. It just has different syntax. And public statics certainly have cleaner code than globals, since you have to qualify them with the class name every time.
If you want a super-robust way to take care of objects that will only have one instance, you might be interested in the "singleton" design pattern.
If you want a super-robust way to take care of objects that will only have one instance, you might be interested in the "singleton" design pattern.
no no no no no.
in before singleton
oh no.. beaten
Don't do it. Globals are bad and singleton is a global. If you have to use globals use namespace. No reason to complicate your code with singleton.
Singleton does not magically cure the problems with globals.
[edited by - captian goatse on January 28, 2004 2:39:36 PM]
in before singleton
oh no.. beaten
Don't do it. Globals are bad and singleton is a global. If you have to use globals use namespace. No reason to complicate your code with singleton.
Singleton does not magically cure the problems with globals.
[edited by - captian goatse on January 28, 2004 2:39:36 PM]
Globals are fine for single-threaded applications. If the program is multithreaded you''ll need to bear in mind that all threads share the globals.
Putting globals inside classes is usually a good idea because it means you''re less likely to get name conflicts between globals.
Using singletons isn''t going to magically make your code any good. Singleton is related to the allocation policy of your objects, not the visibility policy.
CoV
Putting globals inside classes is usually a good idea because it means you''re less likely to get name conflicts between globals.
Using singletons isn''t going to magically make your code any good. Singleton is related to the allocation policy of your objects, not the visibility policy.
CoV
Umm.. Captian Goatse, there is no problem with globals. Just like any other aspect of a programming language, globals have their place. Yes, there are problems that you have to consider when using them, but there are also problems to consider with any other method you have of getting around a problem.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement