Of which bad practice is require calling functions in order a sign?
- by stijn
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?