I'm stuck on a problem that is:
-how to set a precondition for all the methods in class so that any method is invoked, these preconditions are checked and if they are met, the invocation begins. If not, an exception is thrown.
What I need that for? I've assumed that any instance of my class is in some state. And I simply want not to allow some methods to be invoked if the state is not correct.
For example: If my class is Player and his state is DEAD I wouldn't want his level to be increased while in this state.
That example shows exactly what I need. Something like a filters on actions in PHP or something similar.
My point is not to check manually, at the begining of all methods, if the conditions for being in the right state are met. Is there any solutions that meets my expectations? Maybe some design patterns or something?