Inheritance
Wednesday, April 6, 2011 - 06:56
I just read through the source of FLARE. Although the overal source looks nice, there were a few things that I did not like the lack of inheritance.
I would personaly inherit Avatar and Enemy (and maybe NPC) from a common class.
- Common functions like move, has to be coded only once.
- Lists can work on more than one class at the same time.
My question is: Do you want me to fix that? (A good way to start in a project is finding a few small things and fixing them)
Steven
I prefer using composition when possible, rather than inheritance. I think of inheritence as a necessary evil complexity saved for extreme circumstances.
Having a base class for units/entities I'm okay with. Right now there's only Avatar and Enemy so I didn't bother (my style of actually getting a project done: write it sensibly now, refactor it to be pretty later). It would be good to have a Unit class eventually because it'll help with moving NPCs or multiplayer avatars.
It's something floating on my to-do list that isn't a priority (better to write new features than refactor old ones while in Alpha). If you want to take a crack at it though, feel free. Simple is better -- if you spend more than one new class (e.g. Unit.cpp) I might not accept the solution.
Sorry to be a hardass about this, but I'll be the one looking at and maintaining this code for the rest of my life :)
Okay,
If you don't like inheritance I'll take for another part.
It seems to be more difficult than I inmagined anyway, partly due to the difference it the enums (e.g. heroes don't take crits) and partly due to the fact that my svn is not working properly.
Steven
PS: Don't worry, I don't mind (much).
If you would like to outline a base Units.cpp class, it definitely would be helpful to me. I could handle the trickier differences between Enemy and Avatar (just not immediately).
For timeline info: I plan on releasing v0.13 late April and v0.14 late May. That will probably come with a Beta tag and a freeze on major features. A lot of the coding I'll be doing in Beta will be refactoring, mostly to move hardcoded configs into text files. At some point in there I'll probably think about a base Units class, and maybe a separate UnitAnimation component.
I will try to make a design for the new class.
A working code can be found @stevenw.nl/Unit.zip, using SVN version 342, modified classes only. (Sorry, the anti-spamfilter on this forum thinks I am a spammer)
(no guarantee how long this file will stay online)
I have found some cases where inheritance will be dificult. In my suggestion, damage is calculated in the Unit class. This means.
wokste,
Looks pretty good. You kept it simple and that's always great.
Sometime this week I'll look at merging this Unit code in. You, Bonbadil, and I all did some coding over the weekend and it can't be merged easily.
It seems that this topic is not only about Inheritance but also about general development, checked today some dev stats of some open source projects, maybe You also would be interesting (only .h, .cpp files where counted):
project: stratagus files: 5107 lines: 2878685 characters: 60588962
project: spring files: 1916 lines: 512323 characters: 12980590
project: btanks files: 503 lines: 86704 characters: 9530445
project: glest files: 311 lines: 49207 characters: 1092475
project: osare files: 88 lines: 15139 characters: 297715
About osare - In my point of view it's very good - to be able to do such a big work with a small amount of code.
It isn't really fair to compare full featured RTS engines with a halfway done action RPG engine.
Hmm, maybe, and because of this I called it "some analytics", I didn't wrote something like Glest better than Spring because it's codebase is about ten times smaller.
It's definitely not an ultimate criteria, but at least some criteria. In my opinion the size of codebase is somethink like an agility of project - less code means easier to start, less to learn, less time spend on supporting and updating it and less bugs.
I personally did it to define how high is entry point for me in these projects.
With same project order:
Average lines per file: 563, 267, 172, 158, 172
Average chars per file: 11864, 6775, 18947, 3513, 3383
You may be interested in % of comments, too.
Cool article composition vs inheritance http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/
Great article