aspose 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 Spring in Action this week in the Spring 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: 11406
    
  16

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