Class member variables, methods and their state
Posted
by codeMonkey
on Stack Overflow
See other posts from Stack Overflow
or by codeMonkey
Published on 2010-05-27T08:41:53Z
Indexed on
2010/05/27
8:51 UTC
Read the original article
Hit count: 164
How should class member variables be used in combination with class methods?
Let's say I have a class 'C' with a member variable 'someData'.
I call C.getData(), which does not return a value but instead puts data in C.someData. The class that instantiated 'C' first calls C.getData and then uses the data by accessing the member variable C.someData.
I call C.getData() in the class that instantiated 'C' which is a function that returns data.
I myself prefer the second way. But it also depends on the situation and it's a small difference. Is it 'bad' to have class methods that depend on the classes internal state? What are the best conventions?
© Stack Overflow or respective owner