JavaRanch uses a Java program to pick the weekly winners for book promotions. It previously used a serious of classes that went the URLs, parsed the data, went to more URLs, picked some random winners and then output them to a file. These contortions were done because the old software was hard to change. With the new Java based software, we have much more active development. Time for a new approach.
Designing the new pick winners program. (It’s the 3rd iteration of the program and the 2nd I’ve done so I’m familiar with the domain.)
- Decide to make a web based version (servlet)
- Think about what I need from the database.
- Write three DAO methods to get post, topic and user info. While I wrote the integration tests first, I did write the unit tests after the code.
- Start the pick winner class Realize there is a lot of date validation logic (and determining the default week) and rename class to WinnerPickingWeek to encapsulate the date range.
- Start the pick winner class again. Call the three DAO methods tying them together.
- Now add the randomness. My test with 1 post will give me enough determinism to keep the tests passing and useful.
- Added a test for excluding ineligible winners (like Henry and I – the winner pickers)
- Now on to the front end. My servlet needs to make sure you are logged in as admin and then delegate to the processing logic.
This got a useable program that runs much faster. After that I added some jQuery logic to make the page dynamic and even more useful. But that’s another topic – possibly a more interesting one. I’ll post it later in the week.