mardi 28 mai 2019

How Can I Organize and Reduce The Amount of Classes in My Application

I guess this is more of a Design Pattern question than coding question. So here we go... I have an android application that contain many classes and activities. I have classes grouped inside directory according to their function eg: DownloadTask, ScanTask inside the AsyncTask directory. Then I have all all activities inside the activity directory and so on. But I notice that a lot of my code is repeated. For example, I have 3 Activities PingActivity, NetstatActivity, WhoisActivity that basically look entriely the same from the point of view of the code. The only difference is the command their using eg: ping host for PingActivity, netstat -ant for NetstatActivity and so on.. they all instanciate the views from an xml layout that looks very similar since all I have is EditText, button, and TextView. And the classes Call AsyncTask to perform the background process separate from the main thread. With the exception of WhoisActivity which use rest api service to query for domain name. So my question is how can I simplify my design? can I use one single class and pass the command or api depending what menu option the user selected? how can I do that? thanks

Aucun commentaire:

Enregistrer un commentaire