Can anyone provide me with general guidelines as to when I should use overridable methods such as “OnMyEvent”, and when I should use events such as “MyEvent” in C#?
Are there any general design principles that can define what to use?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Events are great for when you have a “has a” while overrides are a lot better for situations where you have a “is a” relationship
For an example, if you have a base class animal, it is likely the case that each animal will have its own way of moving. however every animal is in some way going to want to move.
Now think of a class person that may ‘have’ a pet animal. in this case the Person might react to the animal moving but it wouldn’t actually handle the animal moving.