Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10872
| From | Novice <novice@example..com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Design Question |
| Date | 2011-12-19 13:49 +0000 |
| Organization | Your Company |
| Message-ID | <Xns9FC059C13891Ejpnasty@94.75.214.39> (permalink) |
| References | <Xns9FBFC38D782BCjpnasty@94.75.214.39> <p2FHq.27831$2e7.8589@newsfe18.iad> |
Arved Sandstrom <asandstrom3minus1@eastlink.ca> wrote in news:p2FHq.27831$2e7.8589@newsfe18.iad: > On 11-12-18 08:13 PM, Novice wrote: >> I am trying to make sure I have the right idea in designing a class >> for a game I am writing. >> >> The game is capable of showing the score either during the game or at >> the end. In both cases, I simply display a dialog showing the score. >> If the game isn't over yet, I entitle the dialog "Interim Score". If >> the game is finished, I entitle the dialog "Final Score". When the >> player is given the interim score, the button at the bottom says >> "Quit" and he is returned to the game when he presses it. When the >> player is given the final score, the button at the bottom says "Exit" >> and the game itself ends when he presses it. >> >> At the moment, I have a single class that gets invoked to show both >> the interim score and the final score. That class is passed a boolean >> which indicates if it is an interim score or a final one. Based on >> that boolean, the title of the dialog is set appropriately and the >> button text is set to either Quit or Exit. The actionPerformed() >> doesn't change: Quit causes a dispose() and Exit causes a >> System.exit(0). >> >> While the dialog is simple and works just fine, I suspect I'm >> violating some OO principles by making the behavior of the class >> change depending on what kind of score is being shown. >> >> Am I right in thinking that I should actually have an abstract class, >> maybe called AbstractScore, and that it should have two subclasses, >> Interim Score and FinalScore? AbstractScore could have all of the >> "common code" in it while InterimScore and FinalScore could each do >> the stuff that was unique to itself, like setting the Title >> appropriately, setting the text of the button, and reacting to the >> appropriate button in actionPerformed(). In other words, the >> actionPerformed() in InterimScore would only react to Quit while the >> actionPerformed() in FinalScore would only react to Exit. Then, my >> game should instantiate InterimScore during the game and FinalScore >> when the user wants to end the game. >> >> Or is there a better way? > > I'm with Stefan when he says that an informational dialog of this type > is annoying, and that being able to quit the entire application from > the dialog (if it is a final score) is unusual. I'm with markspace > when he says "At some point you have to stop making objects and just > make the code actually do something" and also with respect to his > comments about separation of concerns. > I realized as I was composing the post that it made more sense to simply show the current score on the main game window all the time than to make the player ask for it and then pop up a dialog to show it to him. But the core of the question still seemed like one that would come up regularly and not necessarily be resolved with a change to the GUI so I finished the question for the sake of future situations that wouldn't necessarily be answered so simply. > Microsoft has an excellent checklist at > http://msdn.microsoft.com/en-us/library/windows/desktop/aa511268.aspx. > I direct your attention to the section "Is this the right user > interface?", and in particular the bullets "Would it be preferable to > use in-place UI?" and "For task flows, would it be preferable to use > another page?". > > Better UI choices would avoid this entire problem. > Agreed. This is actually an older program that I am bringing up to date and I'm trying to be truer to OO principles in it than I was in the original coding. I thought of doing the abstract class and the two sibling subclasses but wanted to make sure that was the right OO approach. But the whole question disappears entirely if I put the score on the main game window and keep it updated as the score changes. > As an aside, "Quit" and "Exit" mean the same thing. "Quit" in your > original terminology is more appropriately "OK". > Agreed. When I first wrote the program, I had the impression that "Quit" meant "dismiss the window but otherwise continue with the program" while "Exit" meant "I'm done with the program and want to end it.". I simply got that wrong. Thanks to you and Stefan for catching that. Now I need to go back over other old programs and replace "quit" with "ok". > As another aside, why the distinction between an interim score and a > final score...anywhere? I'd just have the score as a non-interesting > number. Are you saying that the user cannot quit at any time? > The distinction is that the final score gets shown after all turns are complete while the interim score does not reflect the results of the current turn. Also, the final score is shown automatically as the player is exiting the game while the interim score is shown "on demand" via the player clicking a "Score" button. But those distinctions essentially evaporate now that I'm moving the score to the main game window. > For a different situation - one that truly rates it - your > observations regrading using an abstract class with common > functionality, and overridden specialized methods in the derived > classes, are on point. > Good! Thanks for helping me make sure I was doing that reasoning correctly, Arved. -- Novice
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Design Question Novice <novice@example..com> - 2011-12-19 00:13 +0000
Re: Design Question Arne Vajhøj <arne@vajhoej.dk> - 2011-12-18 19:24 -0500
Re: Design Question ilAn <idonot@wantspam.net> - 2011-12-20 16:47 +0200
Re: Design Question Arne Vajhøj <arne@vajhoej.dk> - 2011-12-20 10:39 -0500
Re: Design Question markspace <-@.> - 2011-12-18 19:23 -0800
Re: Design Question Novice <novice@example..com> - 2011-12-19 13:26 +0000
Re: Design Question Novice <novice@example..com> - 2011-12-19 13:28 +0000
Re: Design Question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-12-19 07:16 -0400
Re: Design Question Novice <novice@example..com> - 2011-12-19 13:49 +0000
Re: Design Question Martin Gregorie <martin@address-in-sig.invalid> - 2011-12-19 22:22 +0000
Re: Design Question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-12-19 20:13 -0400
Re: Design Question Lew <lewbloch@gmail.com> - 2011-12-20 07:37 -0800
Re: Design Question Arne Vajhøj <arne@vajhoej.dk> - 2011-12-20 10:42 -0500
Re: Design Question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-12-20 17:46 -0400
Re: Design Question Martin Gregorie <martin@address-in-sig.invalid> - 2011-12-20 20:40 +0000
Re: Design Question Novice <novice@example..com> - 2011-12-19 13:34 +0000
Re: Design Question Roedy Green <see_website@mindprod.com.invalid> - 2011-12-19 06:25 -0800
Re: Design Question Gene Wirchenko <genew@ocis.net> - 2011-12-19 11:38 -0800
Re: Design Question Lew <lewbloch@gmail.com> - 2011-12-20 07:42 -0800
Re: Design Question Gene Wirchenko <genew@ocis.net> - 2011-12-20 11:51 -0800
Re: Design Question soulspirit@gmail.com - 2011-12-20 14:55 -0800
Re: Design Question Gene Wirchenko <genew@ocis.net> - 2011-12-20 15:25 -0800
Re: Design Question soulspirit@gmail.com - 2011-12-21 01:11 -0800
Re: Design Question Gene Wirchenko <genew@ocis.net> - 2011-12-21 11:08 -0800
Re: Design Question soulspirit@gmail.com - 2011-12-21 15:27 -0800
Re: Design Question Gene Wirchenko <genew@ocis.net> - 2011-12-21 18:06 -0800
csiph-web