Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Desire for a pattern for extensibility

 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My webapp publishes results for athletic events esp.
Track & Field. Each event share some a characteristic:
the order of the athletes, based mostly on time (the fastest first), but may include height or distance. But there are also
many other specific variations in events.
Example 1
---------
Triathlon - your time is an accumulation of the swim leg, the bike leg and the run leg. Thus the results need to show
those times separately and as a total.
Example 2
---------
In some road racing events, the winner is calculated based on
a series of individual races held over several weeks (I think they call this a Grand Prix event). But the results each week is similar to any one off events - it's just that to display the leader board at the end of the season, you'll need another view
which accumulates all the data together.
So back to the question: what design patterns can be applied in
my problem domain ? How do I model a "race result" such that it is extensible to cover other more different events in the future ? Will MVC help me in any way in the presentation side
of the results ?
Thanks
Pho
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I think that the strategy pattern might be worthwhile to apply here. Each "Event" might be implemented as a strategy that implements at least three methods:
(1) public String displayResults(Person p)
// provide a string containing results for a specific person
It probably should implement the Comparator interface and thus:
(2) int compare(Object o1, Object o2)
// Compares its two arguments for order
// This comparison would be unique for each event
(3) boolean equals(Object obj)
// return super.equals(obj) unless you get really fancy...
Thus keep your people for each Event as a Collection and then use the Event to sort the collection.
Kyle Brown


------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to me like you've got some of the characteristics of a composite pattern. Events may be broken down into other events, yet you want to treat all events the same. That is, you have a hierarchy (events), yet you want to be able to get rankings of individual events and grouped events.
MVC may be useful from the display point of view, but won't help you with the modeling of the events.
------------------
Alan Shalloway,
Look for Jim Trott and my book: Design Patterns Explained
Visit our site Net Objectives.
Visit our Design Patterns Explained Community of Practice
Check out our CDROM based audio training in XML
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing we should point out is that using one pattern does NOT preclude using another, even in the same class! Alan and I have focused on different areas of the problem -- I was looking at ranking and display, while Alan was looking at grouping together events and sub-events.
So, the final solution will have elements of both. It's not that you didn't use one but did use the other -- you can successfully use both in the same class.
From the point of view of a JSP (for instance) the Events act as strategies -- different Events act in different ways. Likewise from the point of view of the group of Participants different events act in different ways. However, viewed from the Events themselves, some events are obviously composites of other events.
This is one of the beautiful things about patterns. A good design is often very dense in patterns. Here we've seen two implemented in the same class hierarchy!
For more discussion of a dense set of patterns in one design, take a look at: http://hometown.aol.com/kgb1001001/Articles/Command/CommandJava.htm
and
http://hometown.aol.com/kgb1001001/Articles/JDBCMetadata/JDBC_Metadata.htm
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
[This message has been edited by Kyle Brown (edited October 05, 2001).]
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic