File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Global Components/Good Programming Practice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Global Components/Good Programming Practice" Watch "Global Components/Good Programming Practice" New topic
Author

Global Components/Good Programming Practice

Gulshan Singh
Ranch Hand

Joined: Apr 22, 2009
Posts: 41
So I have a program with a lot of JTextFields and JLabels, and they need to be accessed by all of the functions in a class. I've also learned that its bad programming practice to have a lot of global variables/components. So what's worse programming practice, making about 20 components global, or having your entire program in one long function? Or is there a way to avoid these problems?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10908
    
  12

if they need to be accessed by all the methods of the class, then you should make them member variables of the class:


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Global Components/Good Programming Practice
 
Similar Threads
Can a View use more than one ViewHelper
What is the best way to prepare for the SCJP 6 exam?
Why Servlet return a blank page?
what are dll/exe files?
a question on If else statement.