If you call PerformFunction()
first, then everything will execute in the intended order, where that order is specified in the order of the lines of code in PerformFunction()
. If you call AbstractMethod()
directly, there's no guarantee that MustBeCalled()
will ever be called. However, I notice that you have AbstractMethod()
marked as protected
, which means that outside consumers of your class will not be able to call it directly. They'll have to use PerformFunction()
-- this is good, as there is now only one public way to invoke your internal methods, and that way guarantees the order that you need.
In truth, there is a level at which you can only guarantee that things happen by choosing to write code to make them happen. You can't, for example, guarantee that code is going to implement a game of Tetris except by actually writing that code and choosing to implement it in such a way that it produces Tetris behavior. The type system and the public/protected/private modifiers can help some by preventing some misuse (as your internals are not accessible and thus cannot be invoked by consumers of your module), but they can only go so far. This is such a case.