How should the communication between Model and View using MVC be?

1

I'm trying to implement some small projects using the MVC standard: Within the project framework, I've created the following packages:

  • View: User interaction screens.
  • Controller: I have a class with methods related to user requests, save, change, delete, list.
  • Modal: Class that implements the Serializable method.

As the application is with SQLite local database integration, it has two more packages:

  • DataModal: Contains the project data model.
  • DataSource: Contains the data source, in the same database is created, in this same class I have the method of data persistence. Save, delete and list.

As I understand it, the controller does not communicate with the DataSource, such communication is between DataSource and Model. Should the methods of insertion, update, delete, and list records be created in a separate class in Modal? How would the communication between it and the Controller be, and how does Modal return the information to the View: passing directly, or should it pass to the Controller and the Controller provide this information to View?

    
asked by anonymous 23.11.2016 / 03:09

2 answers

1

Come on.

The methods of insertion, update, removal, and to list the records, should be created in a separate class in Modal?

This will depend on your architecture, you can "decouple" that part by creating a part of the system that does CRUD and then provides the Model with the data and then passes it to Controllers . See DDD .

How would the communication between the Controller and the Modal be, and how does Modal return the information to the View: passing directly, or should it pass to the Controller, and does the Controller provide this information to View? / em>

  • How would you communicate with the Controller?

    To use a Model in Controller , you can instantiate the Model class and access its methods.

  • and how Modal returns the information to the View

When you create a Controller you associate a View with it, and thus you have access to its elements, being able to control them, Model is not aware of Views is Controller quem makes this "bridge" between them.

I suggest you read this post MVC and this article MVC

    
23.11.2016 / 12:10
0

"I understand that the controller does not communicate with DataSource"

The control class, which is nothing more and nothing less than activity, has to communicate with the class that inserts / deletes / modifies the data.

To clarify my thinking: View = XML; Controller = Activity; Model = Entities (bank);

Your bank will have a class that creates it. You can create another class that manages the bank to facilitate the insertion of the data. The activity throws the data in this manager class that receives the view (in fact the data will already be in the activity itself, since xml is an "illusion")

    
23.11.2016 / 13:24