First, check below links for understanding Repository pattern
ProductRepository.php
is the main class to get product data. The repository is a design pattern which allows code separation between data retrieval and business logic and Magento 2 use this design pattern.
You can use Repository also use for Magento REST AND SOAP API and that main advance of the repository. Same class use for both API, frontend, admin area for getting a particular entity data like category, Product, etc.
A repository
is a part of the service contracts. We use service contacts to Implement API point and Service contacts are related with RepositoryInterface and Data interface
Here Product.php
is Data model class which provide
and ProductFactory.php
is the Factory class which uses initiate the data class.
Also, check this MSE answer for understanding when you will use Factory and Repository When Should We Use a Repository and Factory in Magento 2?
From Magento 2.2 version, Magento tried to avoid data using load()
function of Model class and this load()
method is a deprecated method.