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.
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.
Joined: Jun 27, 2010
Okay thanks. I just wanted to double check if my coding practice was fine