Take the following code as example:
// Vendor\Namespace\Model\SomeClass
// ...
public function __construct(
ExampleClass $object
{
$this->object = $object;
}
// ...
I can use argument replacement to configure the object manager to use another class that inherits from ExampleClass in di.xml
:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<!-- ... -->
<type name="Vendor\Namespace\Model\SomeClass">
<arguments>
<argument name="object" xsi:type="object">Vendor\Namespace\Model\AnotherExample</argument>
</arguments>
</type>
</config>
I can also configure a preference to replace the class:
<!-- .... -->
<preference
for="Vendor\Namespace\Model\Example"
type="Vendor\Namespace\Model\AnotherExample" />
<!-- ... -->
What is the difference between these two methods?