I am developing an android app and I have questions regarding the design pattern I should use. Below is the scenario.
The app I develop load data from 10 different data sources. Let's say data source A,B,C,D... All data sources present the data in exact same format. After loading the data it do some filtering and apply business logic. Then the data will be displayed. Regardless of the data source, the data will be displayed in the 100% same format.
In the main screen, there are 10 buttons which tells the code from which data source the data should be loaded, each button dedicated for one data source. Lets call them button A,B,C,D.... Once the button is clicked the Activity for data loading and displaying will open and display the accurate data.
Now, when displaying the data I have been using a single Activity all I have to do is identify which button is clicked and then load data accordingly.
Now I have a requirement where I have to display the 10 data sources in 10 Activities. The reason is, everytime the data will be reloaded in current setup. If I load data source A then load data source B then again load data source A, everything previously loaded will be reloaded, because I am using the same class to hold everything. The loading time etc is really irritating because I cant quickly go and see A data without reloading, if I have loaded B data.If I seperate this into different activities, loaded data will stay as loaded, just one time.
Now the issue is correctly implementing this. copy and paste the same code into 10 Activities is not the correct way. My thinking was to have a one Superclass which takes the data source as a parameter and have methods to do all loading and business logic. This class will hold all variables related to business logic. Then I will have 10 child classes extending the superclass and their job is simply to call superclass methods and display data.
What is your opinion on this? Appreciate to hear any better alternatives too.
Aucun commentaire:
Enregistrer un commentaire