Home > Back-end >  Is right pass hsahMap to repository mvvm android
Is right pass hsahMap to repository mvvm android

Time:02-16

Hi is right pass HashMap to functions in repository

void sendComment(HashMap<String, String> data){
FirebaseDatabase.getInstance(). getRefrence().setValue(data);
}

And in viewmodel i create HashMap var and add key,value to it like

HashMap<String, String> data=new HashMap<>();
data.add("commentText","any text");
data.add("senderId","any text");
data.add("postId","any text");
repo.sendComment(data);

Is that true or should i add arguments senderId,postId,commentText In function in repository Like

void sendComment(String postId,String senderId){
//Add to database code
}

CodePudding user response:

first of all you can use SparseArray instead of HashMap . because SparseArray is intended to be more memory-efficient than a HashMap, because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping depends on your task .

SparseArray<Int>().set(key , value)

you can use the repository for change any object(data) to save in DB or send to the server and change any object(data) to pass to ui and viewModel .

  • Related