Re: An kind of member function name scope specification
Ian Collins <ian-news@hotmail.com> writes:
public:
Account( double const balance );
double balance(); };
No too big a deal here, but in general geters are a design smell.
Yes, but I do not see a getter here. Let me explain why:
I have quoted the public interface of the class above.
It misses an important feature: documentation.
So I will add that document now in the way the names suggest:
- The constructor initializes a new account with
an opening balance as the argument.
- The function ?balance? returns the current balance
of the account.
No mentioning of private fields in the documentation.
So a client/caller/reader of this interface can not know
whether this function returns the value of a private field or
obtains the balance using some other means. He does not know
which fields an object of this class has. Therefore, I do not
deem ?balance? to be a getter, just a non-void function.
I would see a getter, if the documentation would read instead:
- Each object of this class has a field named ?balance_?.
The function ?balance? returns the value of this field.
(Admittedly, my code does not have documentation, so both
interpretations are possible. But the first one was intended.)