constructor should not call methods
- by Stefano Borini
I described to a colleague why a constructor calling a method is an antipattern.
example (in my rusty C++)
class C {
public :
C(int foo);
void setFoo(int foo);
private:
int foo;
}
C::C(int foo) {
setFoo(foo);
}
void C::setFoo(int foo) {
this->foo = foo
}
I would like to motivate better this fact through your additional contribute. If you have examples, book references, blog pages, or names of principles, they would be very welcome.
Edit: I'm talking in general, but we are coding in python.