I need a some design help...
I originally had a class called TeamScore, for handling the score of a game. Which was specific to AFL. (Aussie Rules) Object subclass: #Score instanceVariableNames: 'goals points' classVariableNames: '' poolDictionaries: '' classInstanceVariableNames: '' Score class>>goals: goalsValue points: pointsValue ^self new setGoals: goalsValue points: pointsValue Score>>setGoals: goalsValue points: pointsValue goals := goalsValue. points := pointsValue. ^self Score>>pointsPerGoal ^6 Score>>goals ^goals Score>>points ^points Score>>total ^(self goals * self pointsPerGoal) + self points Score printOn: aStream aStream print: self goals; nextPut: $.; print self points; nextPut $.; print: self total. score := Score goals: 22 points: 11. etc Now.. I then wanted to introduce an alternative Scoring method for Rugby union (and league).. and this is where it gets icky, and I can't see a nice way to abstract it... Union, try (5 points), conversion (2 points), penaltyGoal (3 points), dropGoal (3 points) So I created a Score subclass called ARUScore, and AFLScore... started to push down the variables for afl into the subclass... I ended up with only a few messages left: Score>>total self subclassResponsibility plus a few methods for adding and subtracting scores together. I won't go into the details of the ARUScore... It just sort of feels wrong.. Anyone have a suggestion about a design at all? Ofcourse, I was doing it at 3am this morning and my eyes were hurting, so my brain probably wasn't working very well anyways... |
Sean,
> It just sort of feels wrong.. Anyone have a suggestion about a design at > all? Not necesarily useful, you could have a ScoringObjective (there is probably a better name) that has a type/name (could be symbols to save space), #basicValue, and either a time stamp (and/or backpointer to contest) or a count. Then you can have each one computer its #value and then total them??? Have a good one, Bill -- Wilhelm K. Schwab, Ph.D. [hidden email] |
In reply to this post by Sean Malloy-8
Sean Malloy wrote:
> > I need a some design help... > > I originally had a class called TeamScore, for handling the score of a game. > Which was specific to AFL. (Aussie Rules) UNTESTED...(and N. American "football") Object subclass: #Score instanceVariableNames: 'type points' classVariableNames: Scores Object subclass: #GameScore instanceVariableNames: 'homeScores visitorScores' GameScore>>initialize Scores := IdentityDictionary new at: #touchDown put: (Score new type: #touchDown points: 6); at: #touchDownConversion put: (Score new type: #touchDownConversion points: 1); at: #twoPointConversion put: (Score new type: #twoPointConversion points: 2); at: #fieldGoal put: (Score new type: #fieldGoal points: 3); yourself GameScore>>initialize homeScores := OrderedCollection new. visitorScores := OrderedCollection new. GameScore>>homeScoresTouchDown home add: (Scores at: #touchDown) [etc.] GameScore>>homeScore ^homeScores inject: 0 into: [:total :score | total + score points] GameScore>>visitorScore ^visitorScores inject: 0 into: [:total :score | total + score points] ---- Just looking this over now, it seems the Score object is not needed, but gut-feeling says it should be there. HTH. --yanni |
In reply to this post by Sean Malloy-8
On Tue, 14 Dec 2004 14:17:14 +1100,
Sean Malloy <[hidden email]> wrote: > > I originally had a class called TeamScore, for handling the score of a game. > Which was specific to AFL. (Aussie Rules) > > > Now.. I then wanted to introduce an alternative Scoring method for Rugby > union (and league).. and this is where it gets icky, and I can't see a nice > way to abstract it... > > Union, try (5 points), conversion (2 points), penaltyGoal (3 points), > dropGoal (3 points) How about using a Dictionary with different types of goals as keys and the respective points as values? Then most messages should be generic enough to be kept in the Score class, I guess. Depending on how you work with Score objects, you might be able to avoid subclassing entirely by initializing the Dictionary with appropriate factory methods: Score class>>for: aLeague ^self new; scoringStrategy: (self strategies at: aLeague); yourself > It just sort of feels wrong.. Anyone have a suggestion about a design at > all? You made one yourself ("introduce an alternative scoring method"), but you were too tired to listen to what you were saying :-) > > Ofcourse, I was doing it at 3am this morning and my eyes were hurting, so my > brain probably wasn't working very well anyways... > The main cause for design headaches ... :-) s. |
In reply to this post by Sean Malloy-8
Sean Malloy wrote:
> It just sort of feels wrong.. Anyone have a suggestion about a design at > all? General suggestion: it sounds as if you are focussing on how a "Score" is defined -- on what data makes it up -- and are getting stuck because there's not a lot of commonality between the football variants. You may find it helps to focus on what you are going to /do/ with the Scores instead; if there is real commonality, then that can drive the design (and if it does result in a commonality of /code/ between the flavours of Score then use a common superclass, if not then just don't bother with one). More specific suggestion: I don't know Australian Rules' rules/conventions, but for the other forms of the game there's single numerical "score" which is what matters, and then the breakdown into how the points were accumulated is secondary (and even somewhat arbitrary -- do you want to distinguish penalty tries from "real" ones, for instance ?). So you might find it worthwhile for Score to have a bottom-line score (you could even /call/ it #bottomLine, though I wouldn't myself ;-) and have a #breakdown that was more free-form (perhaps even Dictionary-based). But then, I haven't really woken up yet (still drinking my breakfast ;-) so... -- chris |
Chris,
[snip] > But then, I haven't really woken up yet (still drinking my breakfast > ;-) so... Yes, I often like to have a pint of foaming ale for breakfast too.. Best regards Andy Bower |
In reply to this post by Sean Malloy-8
Sean Malloy wrote:
> Now.. I then wanted to introduce an alternative Scoring method for Rugby > union (and league).. and this is where it gets icky, and I can't see a nice > way to abstract it... I just took a quick look at the different methods/classes. To me it seems that there are different ways (strategies) to calculate the total score. I would take a look at the strategy pattern. As fas as I can see it at the moment this will not reduce the number of classes/hierachies - however this might payoff if you decide to extend Score without having to take care about different GoalCalculationStrategies. Just my 2 € cent. CU, Udo |
In reply to this post by Sean Malloy-8
Sean Malloy wrote:
> I need a some design help... > > I originally had a class called TeamScore, for handling the score of a game. > Which was specific to AFL. (Aussie Rules) > ... > > Now.. I then wanted to introduce an alternative Scoring method for Rugby > union (and league).. and this is where it gets icky, and I can't see a nice > way to abstract it... > > Union, try (5 points), conversion (2 points), penaltyGoal (3 points), > dropGoal (3 points) > > Problem: Keep track of scoring events for various games. Each game has a different notion of scoring rules, which maps event names to a score value for that event. Given an instance of a game (the scoring rules), and of the recorded scoring events, produce the final scores. Hints: 'ScoringEvents' sounds like it might use aBag. 'ScoringRules' sounds like it might use aDictionary. Producing a final score might require a pair of scoringEvents, and an instance of the scoringRules to be used. Regards, -cstb |
In reply to this post by Sean Malloy-8
Thanks for the responses. I'll let you know how it goes.
|
In reply to this post by Andy Bower-3
"Andy Bower" <[hidden email]> wrote in message
news:[hidden email]... > Chris, > > [snip] > >> But then, I haven't really woken up yet (still drinking my breakfast >> ;-) so... > > Yes, I often like to have a pint of foaming ale for breakfast too.. Bearing in mind that it is only possible to get a proper pint of "foaming ale" at the pub, this should enable the observant reader familiar with English opening times to determine fairly precisely the hour at which Andy normally rises :-) Regards Blair |
Free forum by Nabble | Edit this page |