Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to access a common class member (Component) by different objects of a class?

 
sony vijay
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I create two objects of Test Class and call initialize method of Test Class in InitializeTest.java. However, I am passing the same textbox component to the initialize method through both the objects.

Passing same textbox twice looks redundant to me. What is a better way to send the textbox component to Test Class such that it can be used commonly by both objects test1 and test2 ?

I simplified the code for better readability but the task I am trying to achieve is that I need to pass textbox from IntializeTest to Test only once and use it commonly by both the objects test1 and test2. In other words, I do not want to create textbox in Test Class.





 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sony vijay wrote:
Passing same textbox twice looks redundant to me.


In almost all cases that is the right thing to do. It might be the case that it would make more sense for that TB to be a static member variable of the Test class, but that's unlikely. It would only make sense that way if that TB were a property of the class as a whole, which is not the same as being a per-instance property where all instances you're currently working with just happen to have the same value for that property. With a toy program like this, it's not really an issue, but in a real program, you'd almost always pass it as a parameter.
 
sony vijay
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay thanks. I just wanted to double check if my coding practice was fine
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic