How it works...

Pre-event and post-event handlers work in the same way as the other event handlers, but these carry a risk of regression. The events we handle through this technique are not delegates, and the developer did not specifically write the method to be handled in this way: otherwise they would have written a delegate. The reason we are restricted to public methods is because these are considered as a public API, and will not be changed or deprecated without a proper procedure. Protected methods can be changed without warning, and we could, therefore, find that our code no longer works.

Private methods are private for a reason: you can't guarantee the internal class state, or how these will be called.

This also reinforces that we need to be careful when assigning public, protected, or private to a method. Always make your methods as private as possible, as this not only ensures that your code can't be called erroneously, but it also makes it easier for other developers to use your code correctly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.146.237