According to following article Named Constructors The Author suggests using
static factory pattern to construct objects is way better than instantinate with
new keyword. At the begining the idea is appealing(according to some details in article) yes method names are more obvious and it gives a sense that the construction of the class it is not dependent to it's contstructor but class has different behaviours according to different problems on construction level.
<?php $customer = new Customer($name); // We can't "new a customer" or "instantiate a customer" in real life. // Better: $customer = Customer::fromRegistration($name); $customer = Customer::fromImport($name);
But the problem I see here according to this idiom we are using class
functions! And according to the above example it creates coupling issues we have to wrap this
static factories with an injectible factory to decouple from the rest of the application?
Could you please clarify me to understand this. I started to see this idiom all around in PHP community and even in some Java examples.