About the app: This is an android app. The app has two components/ two different users, scorers who score the game and fans who view commentary of the game.
- Scoring User : A scorer watches a live baseball game and puts the score after each pitch/event of the game. These events are pushed to the server and also stored locally in the scorer's phone.
- Fans User : Fans who want to follow the game can view play-by-play/pitch-by-pitch commentary of the game on the fans app sent by the server based on the events sent by the scoring app.
Each game will have set of data associated with the game. Fixed data which wont change through out the game, like -:
- Teams Name
- Players List
- Grounds Name .. ETC
Each match will also have a list/array of events. Each event will contain a number of information.
- Batter Name
- Pitcher Name
- Runs scored
- If wicket taken, how was the wicket taken. .. ETC
These list of events generated in each games are stored on the server. Over a period of time these events per match generate interesting insights about pitcher. Example : how is a pitcher better against left hand batters, how a batsman has better average when team win, etc.
Problems/Suggestions required :
- The scorer might have made a mistake in scoring an event and needs to undo the last event. Which design pattern to use in android to support this?
- Should the events be stored as JSON or POJOs on the android app? After each event on the scoring app the event needs to be stored on the local db and on the server. The data is sent to the server a JSON and dumped in a mongoDb.
- The app needs to store details about each event to display in on the commentary app, also to generate insights. The scorer UI also shows the current batsman, runs scored by current batsman, total, current pitcher info etc. This keeps changing after every event.
All these data can be derived and updated on the UI by two ways:
- Events list is updated after new event and all other derivable data is calculated again by looping the events. So in case of UNDO last event is removed and looping over again would recalculate actual values. This could keep the data accurate and less prone to errors but needs to traverse a long list each time.
- Along with events list there is another data structure that holds values for other info to be displayed on the UI. Events list is updated after new event and all other derivable data is also updated on the other data structure. This could cause mismatch in data cause data is duplicated, but you don't need to traverse the long list of events each time.
I have spent sometime on design patterns but could not take a decision on what to proceed with. An expert opinion/direction or a word from someone who has done something in similar lines would be very helpful.