L
L
loly2016-05-22 06:02:41
Java
loly, 2016-05-22 06:02:41

How to implement a model in MVP? Am I understanding this design pattern correctly?

Actually, at first everything is clear - we have 3 parts - model, present, view, but I have questions about the implementation of each of them in android studio.
As far as I understood from what I read earlier

  1. All layouts are replaced by fragments, so we have only 1 layout with 1 element - FrameLayout (this is the most unusual for me, I understand logically, but it still seems that something is wrong here)
  2. view
    • MainActivity class with fragment replace method
    • A class for each fragment with initial settings like onClickListners in onCreate and methods like makeToast

  3. present
    • Present for each fragment
    • Could there be additional classes in this part? For example, a class responsible for working with user data?

  4. Model
    • I don't understand a little how to implement it so that the data would be available in all present's? Perhaps I misunderstand how this part should be implemented and the model should not store anything in itself, but only receive data from other places (SharedPreferences, SQLite, etc.)? In this case, in each presentation, you just need to create a new model?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Grabko, 2016-05-22
@loly

That's right. Present can refer to another class easily, but it's better not to do that. In fact, Present is an analogue of the controller in MVC, only with additional. abstractions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question