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

Asked

Viewed 848 times

1

I’m trying to implement some small projects using the MVC standard: Within the project structure, I created the following packages:

  • View : User Interaction Screens.
  • Controller: I have a class with methods referring 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 which the database is created, in this same class I have the data persistence method. Save, delete and list.

From what I understand, the controller does not communicate with Datasource, such communication is between Datasource and Model. Should the methods of inserting, updating, removing and listing the records be created in a separate class in Modal? How would the communication between the same and the Controller, and how the Modal return the information to the View: passing directly, or should pass to the Controller and the Controller provide this information to View?

2 answers

1

Come on.

The methods of inserting, updating, removing and listing the records, must 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 the CRUD and provide the Model with the data and then it passes this data to the Controllers. Behold DDD.

How would the communication between the same and the Controller, and how the Modal return the information to the View: passing directly, or should pass to the Controller and the Controller provide this information to View?

  • How would the communication between the same and the Controller

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

  • and how Modal returns the information to the View

When you create a Controller you associate a View to him, and so you have access to her elements, being able to control them, the Model is unaware of the Views is the Controller who makes this "bridge" between them.

I suggest you take a look at this post MVC and this article MVC

  • Jcsaint - Thank you for your help, from your explanation, post and article, I will seek to understand more deeply about this concept and implement here. Big hug, all the best.

  • @Rodrigotiburski... :)

0

"From what I understand, 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/delete/modifies the data.

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

Your database will have a class that creates it. You can create another class that manages the database to facilitate data entry. Activity throws the data in this manager class it receives from the view (actually the data will already be in Activity itself, since xml is an "illusion")

  • Thank you for the information, simple but extremely objective, and of great help to follow the studies. Great hug, all good to you.

  • "The control class [...] has to communicate with the class that inserts/delete/modifies the data." No, it does not, and it should not. Controller should be the most DUMB classes of the application. They take no decision and no knowledge of the application infrastructure. They serve only, and only, to control routes. Who takes decisions are Domains, and these yes receive persistence infrastructure via injection.

  • So...I think that’s what I said. The control only calls the domain and it in turn makes the operations.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.