C# help class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C# help class

What do I need to use polymorphism in c%? Let me explain, what changes if I create an Animal class and then some classes derived from that base and then create objects belonging to the Animal class using the virtual and override functions, instead of creating multiple classes that don't derive from that base? Suppose I want to apply these two types of syntax while creating a game, what changes? Sorry for my English, i’m Italian.

8th Jun 2023, 6:54 PM
Giovanni Paolo Balestriere
Giovanni Paolo Balestriere - avatar
1 Answer
+ 3
Polymorphism is gonna be most useful when the inheriting classes are *mostly* the same, with minor variations. If you're overriding everything every time, yeah you kinda may as well make two separate classes (or refactor your code). If each child class only overrides one or two things though (especially if they're overriding different things), a polymorphic model is gonna be much easier to manage.
8th Jun 2023, 7:17 PM
Orin Cook
Orin Cook - avatar