Skip to main content
GameDev.net gamedev.net
🔒 Locked

A (very late) question about class inheritance

Started by Midnite_Zone Dec 7, 2009 at 2:10 AM 0 replies 1k views
Original Post
Midnite_Zone
Midnite_Zone
Hi everyone. Well believe it or not, someone is still actively participating in this workshop. I first looked into learning to program almost two months ago, and after I chose c# as my language of choice, I found this forum & this old workshop. I've read through week 6 of the lesson so far, and I completed project #1, which I really loved btw. My first successful maze build is printed & hanging on my refrigerator! So here I am at project 2, and I'm pretty solid on all the material in the book. The one thing that I'm not sure about is the "best" way of approaching this project. Sure, there's no single "right" way, but it seems that those of you with programming experience can usually agree the accepted "best" way of laying things out (like the whole idea of using enums to hold all text choices. I guess that was obvious to many of you, but beginners never would have figured it out. Hell, enums aren't even explained in the book)... I know there must be a really good way of laying all this out, but I almost hate to get started without knowing what that is. I'd hate to pour 10 hours into my code, only to realize that I'm doing it all wrong... Am I right, or is that necessary for me to learn? Here's what I'm thinking: -I can make "Race" be a static abstract class (rather than having a class for each individual race). All fields & methods will be protected. This class will hold code for all race-specific modifiers for all seven races. -I can make "CharacterClass" a static abstract class also (it will inherit from the Race class). Again, all fields & methods protected. This class will hold code for all character-class-specific modifiers. -Finally, "Character" will be an instance class (it will inherit from CharacterClass). From inheritance, this class will have ALL the methods to calculate ALL the modifiers for ALL combinations of race & character class. It will also contain all the fields for holding data. So is this a good plan? Will my "Character" class be too big? Do I need to break it down into smaller parts? Is there something really obvious that I'm missing? The way I see it, it shouldn't really matter how big the "Character" class is, as long as it works. But I really want to abide by the principles of OOP, so if this isn't how it's done, please let me know. Wrapping my head around OOP is the only thing I need help with. I can't help but see the solution as one giant messy program... I'm trying to break it into parts (separate classes) but I'm not sure if it's really simplifying my code or not. Let me know! .......................ken
Midnite_Zone
Midnite_Zone
Hmm, I've been thinking about it, and maybe I should make "Character" the parent class, and "Race" could derive from that, and finally "CharacterClass" could derive from that...

description of your image

Could this work? Am I still missing something really easy/obvious?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.