Proper code design for Android/Java -


code design questions

i have class lets area has private instance variable called schools . in area 's constructor initialize schools because time taking process. there instance method in area says group schools list of students passed. group these students schools , pass result.

is responsibility area class has maintain list of schools doing grouping? main question android related: have multiple fragments needs use class. make use of number of schools, list of schools grouping them. dont want instantiate area every single time open new fragment. , how should instantiating them in fragment or place? cant make singleton because area can change , in turn needs reinstantiate itself. cannot call setschools on 1 time thing. ideas? there design pattern can follow?

my thought have class handles creation of areas (possibly application class).

the application hold onto map of areas form of area id. if find area not yet exist, create @ point , store in map other fragments use later.

with regard sorting of students, doesn't seem job of area. perhaps using studentmanager make more sense.

this how imagine (in simplified form):

class student {   string name; }  class school {   list<student> students;    boolean contains(student) {     return students.contains(student);   } }  class area {   list<school> schools; }  class studentmanager {   map<school, set<student>> sortintoschools(collection<student> unsortedstudents) {     map<school, set<student>> result = new hashmap<>(); // should use decorated map here     for(student student : unsortedstudents) {      for(area area : areas) {       for(school school : area.schools) {         if(school.contains(student)){           result.get(school).add(student);         }        }       }     }   } } 

i'm sure can improve studentmanager class sorting separation makes sense me...


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -