I'm studying Magento and I'm confusing about the differences between these four layers. What I have understood is the following:
Model
Is the entity class with ONLY getters/setters and magic methods.
ResourceModel
Is the layer responsible of C.R.U.D operations. This class should contains ONLY the _construct
method to map my entity with the database table.
Collection
As the name suggested, it's a class that implements IterableInterface and give me only a list of Entity.
Repository
It's a class that expose API methods to the external and it's also used to execute operations to database. It's used to save/load/delete entity (internally I think that for these CRUD operations it should use the ResourceModel) and to expose methods to get collections of results.
EntityNameInterface
It's the interface that Model should implement.
EntityNameRepositoryInterface
It's the interface that Repository should implement.
But not all Magento modules work in this way, so there are modules that don't use this approach yet, but for compatibility reasons they use the old approach. Is it correct what I learned to it?