How to get value among subclasses

F

fzl2007

I have four classes that are extended from the same superclass. Each
class need to be able to get the value (rssdid) that the other class
set. How do I do that? I have tried to use the getter and setter. It
seems to work only within one class, other class can't get the value.
It is null.

I am using actionscript but the OO theory should be the same.

This is the class for the variable to share among subclasses.
public class LocalVO {

private var rssdid:String;
public function LocalVO(rssd:String) {
this.rssdid = rssd;
}
public function getRssdid():String {
return this.rssdid;
}
public function setRssdid(value:String):void {
this.rssdid = value;
}
}


This is what I have in the superclass:
public var localRssdid:String;
public var localVO:LocalVO = new LocalVO(localRssdid);

public function setMyRssdid(value:String):void {
localVO.setRssdid(value);
}

public function getMyRssdid():String {
return localVO.getRssdid();
}

This is how I get it in the subclass:
getMyRssdid();

The problem is the value set in one subclass is not accessible to
other subclasses.

What did I do wrong?

I appreciate any input.

Thanks.
Faye
 
A

Arne Vajhøj

fzl2007 said:
I have four classes that are extended from the same superclass. Each
class need to be able to get the value (rssdid) that the other class
set. How do I do that? I have tried to use the getter and setter. It
seems to work only within one class, other class can't get the value.
It is null.

non static fields are set in instances not in classes.
I am using actionscript but the OO theory should be the same.

AS and Java are very different - you may get much better advice in
an AS group.
This is the class for the variable to share among subclasses.
public class LocalVO {

private var rssdid:String;
public function LocalVO(rssd:String) {
this.rssdid = rssd;
}
public function getRssdid():String {
return this.rssdid;
}
public function setRssdid(value:String):void {
this.rssdid = value;
}
}


This is what I have in the superclass:
public var localRssdid:String;
public var localVO:LocalVO = new LocalVO(localRssdid);

public function setMyRssdid(value:String):void {
localVO.setRssdid(value);
}

public function getMyRssdid():String {
return localVO.getRssdid();
}

This is how I get it in the subclass:
getMyRssdid();

The problem is the value set in one subclass is not accessible to
other subclasses.

What did I do wrong?

I appreciate any input.

If this was Java I would say that the class versus instance logic
was completely messed up.

I don't know about AS.

Arne
 
T

Tom Anderson

I have four classes that are extended from the same superclass. Each
class need to be able to get the value (rssdid) that the other class
set. How do I do that?

I think you've completely misunderstood how objects work.

Objects are like things, material things in the real world, like this mug
on my table, or the glass on the coffee table, or the glass you drank from
at lunch. Classes are like kinds of things, like mugs or glasses. Every
object belongs to one specific class - my mug is a mug, my glass is a
glass, your glass is also a glass. Classes can be grouped into families -
for instance, mugs and glasses are both containers - and then you have a
subclass - superclass relationship.

What you're asking is a bit like asking why, when i fill my mug with tea,
there isn't any tea in your glass. The answer is that things just don't
work that way.

tom
 
R

Roedy Green

I have four classes that are extended from the same superclass. Each
class need to be able to get the value (rssdid) that the other class
set. How do I do that? I have tried to use the getter and setter. It
seems to work only within one class, other class can't get the value.
It is null.

if the variable or getter is package/default, or protected scope, all
the children should be able to see mother's variable.

See http://mindprod.com/jgloss/scope.html
--
Roedy Green Canadian Mind Products
http://mindprod.com

"The most significant trend in the US industry has been the decline in the amount
of energy recovered compared to energy expended. In 1916, the ratio was about 28
to 1, a very handsome energy return. By 1985, the ratio had dropped to 2 to 1,
and it is still dropping."
~ Walter Youngquist, Professor of Geology

By 2003, it had dropped to 0.5 to 1 in the US, making oil extraction no longer economically viable, no matter how high the price of crude.
 
R

Roedy Green

Each
class need to be able to get the value (rssdid) that the other class
set. How do I do that? I

Others think your problem might be you are not yet clear on the
difference between a class and an object. If that is the case, have a
look at:

http://mindprod.com/jgloss/class.html#CLASSVSOBJECT
--
Roedy Green Canadian Mind Products
http://mindprod.com

"The most significant trend in the US industry has been the decline in the amount
of energy recovered compared to energy expended. In 1916, the ratio was about 28
to 1, a very handsome energy return. By 1985, the ratio had dropped to 2 to 1,
and it is still dropping."
~ Walter Youngquist, Professor of Geology

By 2003, it had dropped to 0.5 to 1 in the US, making oil extraction no longer economically viable, no matter how high the price of crude.
 
M

Mark Space

fzl2007 said:
I have four classes that are extended from the same superclass. Each
class need to be able to get the value (rssdid) that the other class
set. How do I do that? I have tried to use the getter and setter. It


Unfortunately as Tom said things just don't work that way.

In Java, this is possible by using a static variable in the super class.
However, while the theory maybe the same in ActionScript, I have no
idea how to do it.


package fubar;

public class SharedValues
{
public static void main( String[] args )
{
Base1 b1 = new Base1();
b1.setMessage( "The message" );
Base2 b2 = new Base2();
System.out.println( b2.getMessage() );
}
}


class Super
{
protected static String message;

public void setMessage( String message )
{
this.message = message;
}

public String getMessage()
{
return message;
}

}
class Base1 extends Super
{
}

class Base2 extends Super
{
}
 
F

fzl2007

fzl2007 said:
I have four classes that are extended from the same superclass. Each
class need to be able to get the value (rssdid) that the other class
set. How do I do that?  I have tried to use the getter and setter. It

Unfortunately as Tom said things just don't work that way.

In Java, this is possible by using a static variable in the super class.
  However, while the theory maybe the same in ActionScript, I have no
idea how to do it.

package fubar;

public class SharedValues
{
     public static void main( String[] args )
     {
         Base1 b1 = new Base1();
         b1.setMessage( "The message" );
         Base2 b2 = new Base2();
         System.out.println( b2.getMessage() );
     }

}

class Super
{
     protected static String message;

     public void setMessage( String message )
     {
         this.message = message;
     }

     public String getMessage()
     {
         return message;
     }

}

class Base1 extends Super
{

}

class Base2 extends Super
{

}

Please forgive my ignorance about classes and objects. I have come
from a non object background and now have to continue a project that
was created and left by an OO person. I have tried to gather my
thoughts and summarized the problem and presented it here in hope to
get some help. I obviously have demonstrated more confusion than
anything. Perhaps let me try one more time ...

I am using four viewHelpers (they are classes that extends from the
same super class which is a subclass of another superclass and etc,
designed by this OO person) to retrieve data for four datagrids on a
tab object, each datagrid sits on a tab, a total of four datagrids/
tabs. Every time when a row on a datagrid (of a tab) is clicked, it
will need to pick up the customer ID and retrieve data for the same
customer on the other three datagrids/tabs. My problem is, I don't
know how to store the customer id when the row is clicked so that I
can retrieve the data for the other three tabs for the same customer
id.

Thank you for your time. I appreciate it.

Faye
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top