1) What have we got at the beginning?
Let's imagine that we have at the beginning objects of "Product" type and we have in application two different implementations: "Product1" and "Product2"
class Product1 implements Product
class Product2 implements Product
Let's also imagine that we have some abstract object "Registry" when we can register "Products"
* @var Product
public $products = ;
public function addProduct(Product $product)
$this->products = $product;
Now imagine how looks client, let's see imagine that we always create Products together with adding them to Registry. This occurs many time.
$product = new Product1();
2) Can we improve this ?
Of course we should extract this code (of creating and adding to registry) as it is done in many places.
So let's see to step 2.