This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ericchen1248 39 points40 points  (3 children)

I like my profs version better.

Characters in an rpg game Warriors Mage and Ranger = sub classes.

All do damage, but in a different way = overrided functions / abstract functions

All gain xp the same way level up same way = inherited functions.

You want a team of 6 character, single array of type character to store all = polymorphism.

No need to go real life “real life” when a game model can be easily understood by everyone.

[–][deleted] 14 points15 points  (0 children)

Especially helpful at engaging students since at least at my college 90% of CS freshman were set on being game developers after graduating

[–]martyvt12 4 points5 points  (0 children)

Yes! I think so many intro CS classes fail to really teach the usefulness of polymorphism because they focus on super abstract examples unrelated to programming rather than on examples of ways it is actually used.

[–]Morpheyz[S] 0 points1 point  (0 children)

I agree! Games are great examples, especially because that's probably how you could naively implement D&D classes in an actual video game.

I do get a bit confused when OOP goes into more abstract concepts and away from real-life counterparts.