I have a class CardStack
. I have several classes that inherit from CardStack
e.g. Cascade
, Deck
, Foundation
etc.
Foundation
doesn't need to add any functionality to CardStack
, but for display purposes my app needs to know which of the CardStack
s are actually Foundation
s.
Incidentally, I have no such function CardStack.Display()
(I'm using a model-view-controller pattern where the View
object simply queries the Model
to find out what type of objects it's dealing with).
It seems OK to me, but is there any reason not to do this?
class Foundation : public CardStack
{
};
class Model
{
Cascade cascade[10];
Foundation foundations[10];
...
};
Nothing wrong with this.
Do it all the time.
In the future, there may be a difference in structure, behavior or implementation. For now, they happen to share a lot of common features.
I don't see any technical problem with it, so maybe you're doing this for semantic reasons. In that case, make sure you document the reason it VERY CLEARLY so maintenance programmers later on don't try and change things.
Yep, this is valid and useful. An empty class can act as placeholder for future functionality (as example). Of course, a bit of documentation is in order if the class in question is "connected" to the program in any way ;-)
In your case above, the C++ code generated won't be burdened... but readability of your code is increased.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With