Section outline
-
Lesson 2. Implementation of polymorphism in C#
Objective: is to form in students a comprehensive understanding of polymorphism as a fundamental property of object-oriented programming, which allows using a single interface to manage objects of different types. The student must master the key concepts of the idea of "one interface, many methods", realize the advantages of eliminating program complexity by delegating the choice of a specific action to the compiler, and learn to identify situations that require the use of polymorphic behavior. In the learning process, special attention is paid to distinguishing between the mechanisms of static binding, which occurs at the compilation stage based on the type of the variable, and dynamic binding, which is implemented during program execution in accordance with the real type of the object. Students must master the practical skills of creating class hierarchies using virtual methods (keyword virtual) and their overriding (override), as well as understand ways to restrict inheritance using the sealed modifier. An important aspect is the study of the role of abstract classes as high-level design tools that describe the general concept without detailing the implementation, and the assimilation of strict rules for working with them, in particular the prohibition of creating instances via new. In addition, students learn to implement polymorphism through interfaces, understand their differences from abstract classes, master the mechanisms of multiple inheritance of interfaces and resolve name conflicts when implementing several interfaces simultaneously. At the end of studying the topic, the student should be able to analyze the feasibility of choosing between abstract classes and interfaces, effectively use the type checking operators is and as for manipulating objects, and design flexible programming models that use modern features of the C# language, such as properties for isolating data access logic.