G
G
Grigory Vasilkov2017-01-15 02:39:54
PHP
Grigory Vasilkov, 2017-01-15 02:39:54

Do I understand the model pattern from MVC correctly?

The model consists of classes of three levels
The first level - the level of the data source (database, or a three-dimensional array) - has methods "get data from the source to the RAM (for example, download a file from a remote server to a local one)" - an example from life - the supplier's price list
The second level - the level of a table, a two-dimensional array-collection - has methods "add a line, delete a line, change a line, get a line by number" - an example from life - an excel sheet from a price list for example with products, thus - a table "products"
The third level - the level of a table row, a one-dimensional array - hardly has any methods, rather it is an object that has a strictly defined set of properties, and automatically checks these properties when they change and sets defaults during initialization, has a full set of columns and a unique set columns. Unique in order to be able to calculate its hash for subsequent merging with the elements obtained from the database
. It’s just that something doesn’t add up for me, so the model is a model that “receiving data, business logic, etc.” - but how many words do not use it - it must be implemented somehow, but I don’t understand nicherta
It seems to me that I have complicated it too much or, on the contrary, simplified it.
Now, if we present the model in the form of three levels - there are certainly fewer questions, but then again - why should I let me write a class for the supplier and paint all the entities of the source data, if within the application my task is to transform, and not know how it is stored, and it’s probably more reasonable create a class called something like this
SupplierToDb1Class {} thus creating not objects and collections, but classes responsible for converting from one source to another?
Or maybe for your own database you need just objects and collections to make it easier to combine them, and for each of the remote sources you need just such intermediary classes? In general, I don't understand

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
Kirill Arutyunov, 2017-01-15
@gzhegow

I recommend watching a piece of speech by Dmitry Naumenko from the Yui2 team: https://youtu.be/WL0-bd2Afho?t=5m55s
There he just talks about the difference between the model in the framework and the model from the MVS.

I
Ivan, 2017-01-15
@IvanCher

You imagine that the Model is something concrete, but in reality it is just an abstract layer and you decide which classes are included in it and which are not. In fact, the model contains EVERYTHING that is related to the data and business logic over them. Next comes the implementation, which can be very, very different. For example, there are ORM DataMapper and ActiveRecord design patterns. They are almost oppositely different in implementation, but they are both models. However, there are lower-level architectures, such as Domain Driven Development and Data Driven Development. In both cases, the Model layer can be spread over several application layers.
I'm currently working on a project with Domain Driven, and there the model is simply smeared over a bunch of application layers. How it will be smeared depends on what layers you initially defined for your application.
And your statement that most frameworks do not understand anything about this is complete nonsense. The Symphony framework is just a standard for academic design in PHP. Based on it, Laravel is also a fairly competent framework. There are also Yii, which went the other way, but also very clearly share the MVC model inside, although they provide a lot of opportunities to nagovnokoda and mix everything together.
Here, rather, you do not understand that the model is not something specific, but only one of the 3 components, from the mvc paradigm, responsible for storing and changing the state of data. There can be as many implementations as there are programmers and even more.
Even more vague is how these 3 components from MVC interact with each other. They can interact based on the event model, or explicitly calling each other, and in a huge number of different ways.
Regarding your example, you described the data storage layer passing into the model. The model, in your case, is the 3rd level - a table row (well, maybe a table too). The 1st level you have is the level that should synchronize the model with the data store. Moreover, there can be several such "synchronizers" and storages can be very different. For example ORM and ODM. They will project and synchronize models with data stores, but in fact they do not belong to models, although if we still need to define them only within the framework of MVC, then this will of course be a model. But in mvc there are many things that do not belong to any of these 3 components, but are the connecting links of these components, for example, the same ORM, ODM, validators (sometimes they are sewn into the model, although they can be used outside), routing ,

R
Rou1997, 2017-01-15
@Rou1997

The model consists of classes of three levels

Rave!
It’s not clear, is it really so difficult to guess that in order to understand what a model is, it’s enough just to see this model and work with it, that is, download some MVC framework, write on it and study its code?
But no, we will read some theory from God knows where, strain our imagination and thus try to understand something, only the road through the tonsils, only hardcore!
The model is one class that represents one of the rows of the database table, the class itself (or rather, the class object) is the current row, the class fields are the cells of this row.
Everything else depends on the specific framework.

T
T_y_l_e_r, 2017-01-15
@T_y_l_e_r

https://www.youtube.com/watch?v=SRacpbuG6Es

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question