global variables in main()

is it bad oop practice to keep all your global constants in main() and have your other classes access them from there?

also, would anyone happen to know of a good online resource that addresses proper oop practices and goes beyond explaining the foundation stuff like inheritence, encapsulation, polymorphism, etc.?

[328 byte] By [pete_c12a] at [2007-10-2 21:45:53]
# 1
not only is it a bad practice, it can't actually be done. variables declared in a method are only available to that method
georgemca at 2007-7-14 1:01:27 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
Sorry, I meant the Main class, not the method.
pete_c12a at 2007-7-14 1:01:27 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

if all of your constants are specific only to the application, then keeping them in the main class won't hurt anything.

however, if you are going to create a class, say circle, and wanted to define a constant BigDecimal that was an EXTREMELY accurate version of PI, you would not want to put that in your main class, you would want to put that in your circle class, because that way you have access to it where ever you use the circle class.

so my answer is, put it in the class it is most closely related to.

- Adam

guitar_man_Fa at 2007-7-14 1:01:27 > top of Java-index,Other Topics,Patterns & OO Design...