Reputation: 19288
I have a time registration app and some users requested to change to first day of the week according to their preferences. I know I can set the first day of the week on a calendar object, but I'm working with a lot of them and I don't feel like setting the first day on all of them. So is there a way to set the first day for my entire app?
Upvotes: 0
Views: 87
Reputation: 39846
I don't feel like setting the first day on all of them
There's a golden rule on software programming that says "Don't repeat yourself", also known as DRY rule. So you shouldn't write the same code again and again to set the first day of week, but some code still should do it for all of them, so....
On those cases, the common way is to build a factory.
class CalendarFactory {
public static void setFirstDayOfWeek(Context context, int value){
// use context to save value in SharedPreferences
}
public static Calendar newInstance(Context context) {
// read the value from SharedPreferences
// create new GregorianCalendar
// setFirstDayOfWeek
// return
}
}
then it's just make sure to acquire instance of calendar ALWAYS through this method.
Upvotes: 2