On Sun, 15 Mar 2015 09:22:02 -0400, Richard Damon wrote:
>> What I fdon't like about the above design is that there's not any
>> OO'ness about it.
Others are doing a fine job of helping you with your design question, I'd
just like talk a little about good C++ design.
Object-orientation is *tool*, not a *goal*. Important goals in software
design are correctness and clarity (always first and foremost),
simplicity, and suitability of purpose. In my lexicon, suitability of
purpose is how well does the code do its current and future job. If
code needs to be able to rapidly adapt to rapidly changing requirements,
flexibility is important. If it's in a performance-critical application
and performance has been measured to be a problem, efficiency becomes
important. Otherwise, what counts is does it do what it's supposed to?
If code isn't correct, it won't be suitable for it's purpose, regardless
of how efficient or flexible it is. If your code is sufficiently
efficient for its purpose, you should put it efficiency aside as
unimportant -- at least until you you have mastered writing code which is
good from these other, more important criteria. Same rule applies to
flexibility. With time you'll get a feel for what flexibility you need
to plan in in advance. Usually, you ain't gonna need it (YAGNI).
In my experience working with novice developers, if you focus on
correctness, simplicity and clarity, you typically wind up with more
flexible and efficient code than if you focus on efficiency and
flexibility in advance. Sad but true.
C++ supports generic, procedural, OO and functional programming. The
best C++ design makes good use of all three of these paradigms. My
impression is your goal is to improve your OO skills with this project,
which is laudable. So it's okay if you focus on OO for the sake of this,
or some other project. If however you see an area where using one of the
other paradigms seems simpler, that's what you should use. Here simpler
means simpler code, simpler design -- which usually means less code, less
multiplication of entities (classes, functions, lines of code). If you
make the decision to do something that isn't very OO, but produces
simpler, easier to read and maintain code, you have just practiced a
*very* useful skill: the wisdom of when *not* to use a language feature.
If on the other hand, using a class hierarchy seems to flow naturally
from the problem you are investigating you should do so. If in doubt,
sketch out an alternative (even a less OO one), and compare the
complexity of the two solutions. Which one more simply solves the
problems you will concretely have to face. Don't speculate too much
about possible, 'maybe we'll need' scenarios. That way lie dragons. A
good question to ask yourself before implementing a hierarchy is: will I
use these sub-classes as base-class? If the answer is no, inheritance is
probably the wrong way to accomplish what you are trying to accomplish.
Good luck
Glen