File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Desire for a pattern for extensibility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Desire for a pattern for extensibility" Watch "Desire for a pattern for extensibility" New topic
Author

Desire for a pattern for extensibility

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

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

Regards,

Pho
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
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.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Alan Shalloway
Ranch Hand

Joined: Sep 26, 2001
Posts: 60
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


Alan Shalloway.<BR>Look for Jim Trott and my book: <A HREF="http://www.amazon.com/exec/obidos/ASIN/0201715945/ref=ase_electricporkchop/103-0514572-3811868" TARGET=_blank rel="nofollow">Design Patterns Explained</A><BR>Visit our site <A HREF="http://www.netobjectives.com" TARGET=_blank rel="nofollow">Net Objectives</A>.<BR>Visit our <A HREF="http://www.netobjectives.com/dpexplained/index.html" TARGET=_blank rel="nofollow">Design Patterns Explained Community of Practice</A><BR>Check out our <A HREF="http://www.netobjectives.com/xml/xml_cdrom_info.htm" TARGET=_blank rel="nofollow">CDROM based audio training in XML</A>
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Desire for a pattern for extensibility