Of which bad practice is require calling functions in order a sign?
Posted
by
stijn
on Programmers
See other posts from Programmers
or by stijn
Published on 2012-06-08T06:52:50Z
Indexed on
2012/06/08
10:47 UTC
Read the original article
Hit count: 275
design
|bad-habits
Sometimes I find myself writing comments on class methods like this:
class A : public Base
{
public:
/**
* Sets variable;
* should be called before ImplementsInterfaceMtehod(),
* else has no effect.
*/
void SetSomeVariable( var_type value );
virtual void ImplementsInterfaceMethod();
}
The callers of Base::ImplementsInterfaceMethod
obviously do not know about the variable, and should not. But the users of A
should set the variable if they want it to take effect. It is not required to set the variable (else it could be a parameter for the constructor), so I cannot throw exceptions in ImplementsInterfaceMethod
if it is not set.
Is this a sign of some typical bad practice? Is there a better way than writing a comment as shown to deal with this?
© Programmers or respective owner