• Welcome to Valhalla Legends Archive.
 

Inheritance question

Started by MoNksBaNe_Agahnim, October 11, 2004, 10:21 PM

Previous topic - Next topic

MoNksBaNe_Agahnim

Not sure if this deal with inheritance but here it goes. I am using netbeans and making an applet. I have two forms and I want to use the variables declared in form1 in form2. How would I got about this?

MyndFyre

You either need to make them available as either public members or through public getter and setter functions.  Both are bad practice, IMHO, and it's better to encapsulate these kinds of multi-UI-element-variables elsewhere.  For example, with settings interfaces in my bot, I have shared settings encapsulated in a single class with a ton of variables.  Then the six or seven client classes that need access to these variables just get a reference to that object.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

The-FooL

Getters/Setters are probably best.  Another option, depending on what your actually doing, is just to pass the variables through method or constructor calls.  Also, instead of multiple references to a settings class, you can make a settings class static and get them without a reference.

MoNksBaNe_Agahnim

could I get some examples. I am such a noob and before I stopped programming I didn't get into encapsulation. Appreciate the help guys!

MyndFyre

Quote from: The-FooL on October 12, 2004, 06:24 PM
Getters/Setters are probably best.  Another option, depending on what your actually doing, is just to pass the variables through method or constructor calls.  Also, instead of multiple references to a settings class, you can make a settings class static and get them without a reference.

In my case, it wasn't an option to make settings static, because I wanted to be able to have multiple connection instances using multiple settings sets.  But you are indeed correct; if you have only one use for them, then static members would work just as well (but remember, you still ought to encapsulate them with static getters/setters!)
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

CrAzY

public double num1 = 1.0;

Get the concept?
CrAzY