You have a conditional expression that selects different behaviors based on the object type.Place each branch of the conditional expression into the override function of a subclass, and declare the original function as an abstract function.
Motivation: the most fundamental benefit of polymorphism is that if you need to take different behaviors based on different types of objects, polymorphism makes it unnecessary to write certain conditional expressions.
Because of the polymorphism, you will find that "switch statement of type" and "If-then-else statement based on type name" are in the object-orientedProgram.
Polymorphism can bring many benefits to you. If the same set of conditional expressions appear in many places of the program, the biggest benefit is the use of polymorphism. When using conditional expressions, if you want to add a new type, you must search for and update all conditional expressions. However, if polymorphism is used, you only need to create a new subclass and provide the appropriate functions in it. Class users do not need to understand this subclass, which greatly reduces the dependency between various parts of the system and makes the system upgrade easier.