Introduction
Polymorphism is one of the core concepts of object-oriented programming. Polymorphism enables objects of different types to be treated as objects of a common base type, providing flexibility and reusability in code.
Suppose you're working at a non-profit company that's in the midst of a software update project. The application combines tightly coupled models with a loosely coupled reporting structure. You're tasked with implementing polymorphism in the application to enhance flexibility and maintainability. You need to understand how to implement polymorphic behavior using class inheritance and interfaces. This module guides you through these concepts and provides practical examples to help you apply them in your work.
The topics covered in this module include:
- Examine the principles of polymorphic behavior.
- Explore inheritance-based polymorphism.
- Explore interface-based polymorphism.
- Review polymorphic design considerations.
- Implement polymorphism in a C# app.
After completing this module, you're able to:
- Explain the principles of polymorphism in C#.
- Implement polymorphism by using class inheritance.
- Implement polymorphism by using interfaces.
- Choose the approach to polymorphism that matches scenario requirements.
- Implement inheritance-based and interface-based polymorphism in a C# app.
By the end of this module, you have a solid understanding of polymorphism in C# and you're able to implement polymorphism using class inheritance or interface implementation.