0
Composition instead of inheritance c#
I have a class Monster { move() attack() } we can create: melee monster : monster overr attack() ranged monster : monster ovverr attack() flying monster : monster overr move() swimming monster : monster overr move() how to create FlyingRangeMonster and MeleeSwimmingMonster without duplicating code? I suppose we should abandon inheritance and use composition. How to realízate it in this case ? Thank you!
2 Respostas
+ 3
How about an interface monster with methods move and attack
0
but if we create an interface we will duplicate code (e.g. melee monster and swimmingmeleemonster will have same realization of attack method)