The Artima Developer Community
Sponsored Link

Java Answers Forum
static variables

4 replies on 1 page. Most recent reply: Nov 26, 2002 2:05 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
clau

Posts: 3
Nickname: clau
Registered: Nov, 2002

static variables Posted: Nov 25, 2002 3:58 AM
Reply to this message Reply
Advertisement
I've created a wizard. I have a Wizard class and a WizardPanel abstract class. In the Wizard class i need some global variables that can be changed by all the wizard's panels (classes that extend WizardPanel). My question is:
I declared the global variables in the Wizard class static. It's working, but i'm wondering if i could avoid to use static variables there. Could you recommend me a better solution?


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: static variables Posted: Nov 25, 2002 1:10 PM
Reply to this message Reply
People are protesting globalization for a reason, you know.

Why can't you have a settings object or something of the like passed from one sheet to another?

clau

Posts: 3
Nickname: clau
Registered: Nov, 2002

Re: static variables Posted: Nov 25, 2002 11:34 PM
Reply to this message Reply
I was told to use some kind of factory or something like that. What do you think about that? Thanks in advance.

Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: static variables Posted: Nov 26, 2002 10:06 AM
Reply to this message Reply
The latest Java Developer Journal mentions 'patterns' in a humurous way. It's your choice to use things like factories or their like. However, I'm inclined to agree with Matt and use a setter-getter. It all comes back to data structures anyways and my preference is to what comes easy to me. You know, that whole K.I.S.S (not the 70's band !) thing. Use what works for you.

Ray.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: static variables Posted: Nov 26, 2002 2:05 PM
Reply to this message Reply
A factory creates objects for you, so that you don't have to be too tightly coupled to the exact type of object. I'm not sure why you would need a factory for what you've mentioned here.

Really a wizard is just a substitute for a large dialog box; it is just a tool to keep the user interface a little simpler and cleaner and to provide a sense of order to the user. In the end, it is just collecting a set of choices from the user and then acting on that information.

I'm not sure how you have all your stuff structured, but if the panels are inner classes of a main frame that has the context information of your app (a reference to an object) then they should be able to pass the information directly. Alternatively, a reference to an object could be passed from panel to panel. This object could either be a settings object, or the actual object that does the work of your app, depending upon which gives you a better design. One of the benefits of using a settings object is that you can easily pre-configure it via a text file, which will facilitate the unit tests (which you've already written, of course).

Flat View: This topic has 4 replies on 1 page
Topic: Multiple event handler and how to select Previous Topic   Next Topic Topic: Servlet Communication

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use