Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Classes and Components Question

Status
Not open for further replies.

mfalomir

Technical User
Feb 6, 2003
78
MX
Hi, I have Class A (extends Applet btw), where I declare a TextArea that I use for tracing results, and Class B where I define some methods, and that it's used by Class A. Is it possible to use the same trace textArea withing Class B ? So that I can trace some results or Exceptions that methods within class B could possibly throw, in the same trace textArea ?

Thanks in advanced :)

 
Yes, it's possible, and there are a few ways to do that.

One simple way is passing a reference of class A to class B so class B can acces the TextArea.

Cheers,

Dian
 
I think it will work if you make the TextArea a field of Class A. Then, so long as your application instantiates a Class A object, say CA, then Class B can refer to CA.<TextAreaName>.

I'm fairly inexperienced but I think that will work.

_________________
Bob Rashkin
rrashkin@csc.com
 
Hi Dian, thanks for your reply :) If a have an abstract class and cannot instantiated it like

myAbsClass newObj = new myAbsClass ( trace );

how can I pass the trace by reference to it ?

Thanks!

 
Why is myAbsClass (which should be capitalised by convention, BTW) abstract, then?

Anyway, you shouldn't expose the things in a class to direct outside influence. That increases coupling. If Class B used the TextArea member of Class A directly, then it becomes more difficult to update the behaviour of Class A in the future. Have a method, such as trace(String message), in Class A. How Class A applies this is encapsulated within itself. If you want to update this later, perhaps writing the trace text to some other resource, you can simply make the change in Class A without affecting other Classes cos these just go through the trace method as usual.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top