This confuses me, in the most simplest terms what does it do? Pretend you are explaining to your mother or someone almost please.
For the record, in easy words, a factory like @Pindatjuh said, returns a object.
So, what's the difference with a constructor? (that does the same)
Constructor is called when each instance is created. Sometimes you don't want that.
For example, let's say that every time i creates an object of the class Account, i read from the database a file and use it as a template.
Using constructor:
class Account {
var $user;
var $pwd;
var ...
public __construct() {
// here i read from the file
// and many other stuff
}
}
Using factory:
class Account {
var $user;
var $pwd;
var ...
}
class AccountFactory {
public static Create() {
$obj=new Account();
// here we read the file and more stuff.
return $obj;
}