0

I have a common variable errorCollector, and the 2 below approaches works for me. But I cant figure out which is best or which is standard?

Approach 1 : Creating a common class for that variable then extending it.

class QAErrorCollector
{//This class is created only for this variable alone.
    @Rule
    public ErrorCollector errorCollector = new ErrorCollector();
}


class TestFeatureA extends QAErrorCollector
{

// use errorCollector
}

class TestFeatureB extends QAErrorCollector
{

// use errorCollector
}

Approach 2: Creating 2 different variables for each class. (This approach will work too in test case)

class TestFeatureA
    {
        @Rule
        public ErrorCollector errorCollector = new ErrorCollector();

        // use errorCollector
    }

    class TestFeatureB
    {
         @Rule
        public ErrorCollector errorCollector = new ErrorCollector();

        // use errorCollector
    }
Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77
  • 2
    possible duplicate of [Inheritance vs. Aggregation](http://stackoverflow.com/questions/269496/inheritance-vs-aggregation) – PsiX Apr 28 '14 at 08:51
  • Do you want a new instance of `ErrorCollector` in each class, or would it be OK to use the same instance in each TestFeatureA, TestFeatureB, etc.? – Illidanek May 22 '14 at 09:39

0 Answers0