To class variable or not to class variable?
===

I got a class `Foo` having a method `doSomething` that uses two class-related variables `b` and `c` that are expensive to get/create. My first version looks like this:


    public class Foo {

        private final A a;

        public Foo(A a) {
            this.a = a;
        }
        
        public void doSomething() {
            final B b = a.getB();
            final C c = b.getC();

            for (int i = 0; i < 1000; i++) {
                // do something with b and c
            }
        }
    }

So I get the first object (type `B`) via a class variable `a` and the second object (type `C`) via the first object.

Now, since those variables are related to the class and the method is *always* called exactly one time (though not necessarily when creating an object of type `Foo`), I thought about making them class variables as well:

    public class Foo {

        private final A a;
        private final B b;
        private final C c;

        public Foo(A a) {
            this.a = a;
            b = a.getB();
            c = b.getC();
        }
        
        public void doSomething() {
            for (int i = 0; i < 1000; i++) {
                // do something with b and c
            }
        }
    }

I'm not sure which version to use if any of those two. I somehow don't feel comfortable making those two variables class members since they can be retrieved from the existing class variable `a`. However, it would increase readability of the methods IMO.

Thanks for your input in advance.