How my application works is once a user opens it, it will open to a screen where it will find out depending on the button the user clicks, how many holes of golf they want to play (18 or 9.) From there it will launch the main activity where, depending on what the user chose, will depend on the rules of the application. ie – If they choose 18, the save button wont activate until the 18th hole, same for 9, it will activate on the 9th hole. This will also trigger a final score notification, etc.
Im curious if I should create a separate class for 9 holes and 18 holes, or if I should just pass some sort of value from the open screen, to the main activity that sets the values at 9 or 18?
I guess I am curious on this programming etiquette as I am not very familiar with the best practice of something like this.
Entry screen will look something like this as of now (I have not finished 9 hole button or help button but will be the same as 18 unless launching a seperate class)
case R.id.button18Holes:
//*********************************//
//***LAUNCHES ACTUAL APPLICATION***//
//*********************************//
Intent myIntent = new Intent(src.getContext(), EasyPar.class);
startActivityForResult(myIntent, 0);
Intent iStartValues = new Intent(this, EasyPar.class);
String[] startValues = new String[] {"18"};
iStartValues.putExtra("strings", startValues);
startActivity(iStartValues);
break;
case R.id.button9Holes:
break;
case R.id.buttonHelp:
break;
}
Im not sure if that string array is the proper way to pass one to another activity either?
Thanks in advance!
Pure OO people would say you should create an abstract base class containing common operations and fields, and then for the specialisations, create sub classes. Case statements and if statements like you have above are not pure OO.
Same goes for arrays in general – in pure OO you might have them as a field in a class, but any operations performed on them would be inside a class.
Personally, I would say go with whatever you think will be easier to maintain, quicker to program and more obvious to other people reading the code. I guess that doesn’t really answer the question though 🙂