Reputation: 62519
I have read this impressive article on data modeling in android with clean architecture and MVP.
Now i would like to refactor some existing models that i have in my domain so that they for one do not contain parcelable code (android code) and are streamlined to work in the specific view. You know sometimes we have to alter the model so that it works in a view like for example to get the selected position in a RecyclerView we would add a field called "selectedPosition" to the model. There are many times we need to change the model and then we end up with models that are not pure and a little hard to maintain.
Specifically i have 3 model data for 3 payment systems i am using. All the fields in the 3 models come back different. they have different names for the fields. Can someone show me an example of the architecture used to make all 3 models use a common model ?
Upvotes: 1
Views: 2118
Reputation: 1705
Data model
I am sure that your 3 models for 3 payment systems have common features. So you can take this features and put it to interface. Each of your models must implement this interface. In your case it should display a data model.
For example:
class Info {
int id;
String cardNumber;
.......
}
interface ITransactionable { //or abstract class with the common func and prop
void addUserWithCard(String cardNumber, String name);
boolean makeTransaction(\*some params*\);
Info getPaymentUserInfo();
}
class Model1/2/3 implements ITransactionable {
\*In each case methods doing different job but give you same result,
you can take info for your models from servers, clouds, db...*\
}
Domain model
Domain model represent your business logic, manipulating of your data model.
class DonationService {
ITransactionable paymentService;
DonationService(ITransactionable paymentService) {
this.paymentService = paymentService
}
Info makeDonation(int money) {
paymentService.addUserWithCard("4546546545454546", "Vasya");
paymentService.makeTransaction(money);
return paymentService.getPaymentUserInfo();
}
........
}
Each layer must give to next something like API.
Presentation
For example can fill recyclerView with data of each transaction. And take events from view like get detail info about transaction or make new transaction.
You can check this for watching how it can be realized: https://github.com/android10/Android-CleanArchitecture
Upvotes: 1