I need to run a certain function before every Function of my class. (Not once in a constructor). It basically needs to happen within that function but at the beginning.
I also don't want to do this:
class A {
shouldRunFirstFunction() {}
functionA() {
shouldRunFirst();
doOtherThings();
}
functionB() {
shouldRunFirst();
doOtherThings();
}
functionC() {
shouldRunFirst();
doOtherThings();
}
functionD() {
shouldRunFirst();
doOtherThings();
}
}
I think in other languages you can extend from class B and then do something their so a certain function gets executed before a function of class A gets executed.
It sounds like you want two (or more) classes. One strategy is to put your implementation in one, management in another:
To use:
I don't know your exact use case, so it might be something completely different, but separating the control from the implementation might be what you want.