I'm having problems using Clean Architecture. For those of you who have read Fernando Cejas' blog post, my question is based on it, and his code.
His example project has only one Domain Object a User. And everything is clear with POJOs. Where I am having a problem is, let's say that the user has books. A one to many relationship. How would you deal with this in Clean Architecture?
Just like him I have a few layers, so 3 classes per Domain Object (User, UserModel, UserEntity) and a repository per Domain Object (UserDataRepository). Our new example would also have Book, BookModel, BookEntity and BookDataRepository.
I also have use case classes with CRUD variations.
The problem for me is at the UI/Presenter level. At this point in the program I have a UserModel object AND a list of BookModels. I do not have userModel.getBooks(). I do not have userModel.save() (which would save all the book changes too).
To accentuate the problem, to make this analogy look even more like my actual use case, I also have the list of all the pages in the books! :) So when I save the User, I want to save to books, and all the pages for every book that might have been modified.
How would I go about this?
Second BONUS question : In my real world problem, I have classes that derive from a base class. To use the above analogy: LeftPage and RightPage would derive from PageBase. A Book has a list. However LeftPage and RightPage both have their separate repositories, separate use cases, etc. (But this doesn't work) How do I save a list ?? Do I have to make a separate use case SavePages which would have a :
if (pages.elementAt(i) instanceof LeftPage) { SaveLeftPage saveLeft = new..... } else { SaveRightPage saveRight = new..... }
I don't think that I can use Polymorphism because in all the documentation that I have seen, the Models don't know of the use cases.
I hope that you can help, thank you very much for your time :)
-MIke
from Newest questions tagged java - Stack Overflow http://ift.tt/1EgySUz
via IFTTT
Aucun commentaire:
Enregistrer un commentaire