How to use class variables?
How to use class variables? A simple question. If I have class A with methods m1 and m2 . Is it a good practice that m1 changes the state of A . And then when m2 is called it relies on A 's state being changed by m1 . In other words if m2 is dependent on m1 being called before m2 being called. With m1 and m2 being both private. Worded differently is it O.K. for private methods to consider the object state as shared memory? Problem arises when they are called out of order. But with the benefit of not having to copy arguments. Any advice? 1 Answer 1 Your description is not a good design. Class variables should have class invariants that are true before and after any (and all) method invocations. The order of calls should not matter. The way you described it make is sounds that there will be cases during which this will not be true, for example if m1 is not called yet and m2 is. Moreover...