|
 |
So I have a generic "game" system. The base "game" is abstract, and there's
a bunch of "screen" classes you can stack up (like "main menu" is under
"start menu" is under "select players popup" and etc.)
Now, a bunch of the abstract screens (like "pause menu" and "join network
game menu") are all supposed to have the same "background" behind them. The
framework I'm looking at has all the classes that are that sort of menu
(i.e., that want to show a generic background (like a scrolling starfield,
or some scene from the game, or etc)) inherit from "backgroundscreen", which
you copy and replace for yourself. I.e., all these are cut-and-paste
programming.
I'd prefer to have a "please log in" screen that's going to be the same menu
and behavior but different background all be concrete, inheriting from an
abstract class you replace for each game.
So, basically, I want a bunch of concrete library classes (A), all
inheriting from the same game-specific class (B), which in turn inherits
from an abstract library class (C).
I'm pretty sure even multiple inheritance would be unhappy with that.
Something like Python or Ruby could monkey-patch the inheritance tree at
run-time, but that's awful.
Right now, I have three solutions. Each (A) class inherits from a concrete
version of (C), which calls a game-specific factory-like method with the
type of (A) as a parameter to draw the background.
Alternately, each (A) actually stacks a (B) underneath in the screen stack,
and I fix the manager of the screen stack to draw the screens underneath
first, and then make sure the (A) classes don't clobber the background
already drawn.
Alternatively, I make the "draw a background" a completely separate
component that gets turned on or off depending on whether the code wants the
background, or depending on the top-most screen of the screen stack. This is
kind of what I'm leaning towards.
But I thought it was an interesting question in OO Design.
--
Darren New, San Diego CA, USA (PST)
Linux: Now bringing the quality and usability of
open source desktop apps to your personal electronics.
Post a reply to this message
|
 |