See the link:
Magento 2 use oops concepts of PHP.
. As the interface is not able to provide a method (function) definition, So, at Magento, every interface is overridden by a PHP class.
Let me give an example, If you want to get an order data then you have to use
If you check at this interface class you will find that only method signature is exiting that interface.
* Loads a specified order.
* @param int $id The order ID.
* @return \Magento\Sales\Api\Data\OrderInterface Order interface.
public function get($id);
That interface is overridden by PHP class
\Magento\Sales\Model\OrderRepository where you find the function definition and its business logic.
This write is managed from di.xml.
<preference for="Magento\Sales\Api\OrderRepositoryInterface" type="Magento\Sales\Model\OrderRepository"/>
If you want to create an object of class at core php then you are write like
$object = new MyClass;
Adding an interface to __construct() means you are creating an object of a class/interface.
public function __construct(
You have created an object of class
ConfigInterface which is $config. which basically create object of
So you can access all public methods of
As at di.xml 's
Magento\Framework\Indexer\ConfigInterface override by
Magento\Indexer\Model\Config, So basically you can access of all public
<preference for="Magento\Framework\Indexer\ConfigInterface" type="Magento\Indexer\Model\Config" />
Adding Interfaces/classes to
__construct() method you are creating an object of that class/interface which required for your work.
And this is the concept of use interfaces at contract().
Also, interface only expose public method NOT your private and protected methods that make your code Core more secure.