I’ve heard about how base classes and method overriding can be combined to eliminate code reuse/write neater code.
Is there an example available of how this can be done (in C#)?
Thanks
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.
Basically, you factor out common functionality from a set of classes that you have created and put that functionality into a base class. Then, when each class inherits from the base class, they receive that functionality (or can choose to override it and provide their own implementation). The code that provides the functionality remains in the base class, in one place, instead of across your set of classes.
Here is a good discussion on that as well as how polymorphism fits in. There are many good books on this subject.