tags:

views:

110

answers:

2

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

+3  A: 

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.

JP Alioto
@JP - Thanks for the BlackWasp link!
Doug L.
A: 

I think a good way to learn about the power of polymorphism is to take a look at Bob Martin's SOLID principles of OOD and also to study design patterns and their use of polymorphism to provide solutions to common problems. I recommend Head First Design Patterns for the later.

Jon Erickson