Hello all, I'm currently reading about the factory design pattern, and I understand it, whereby you can instanciate a class within a class like so
PHP Code:
Class Factory {
public function doSomething($value) {
switch($value) {
case 'A' : return new ClassA; break;
case 'B' : return new ClassB; break;
}
}
}
$obj = new Factory();
$obj->doSomething('B');
However, I'm not too sure as and when to use it.
Say I was building something like a website or something involved in creating a website element, how could I use it here? Can anyone help me with an example to see if I can figure out how to use it in my projects?
Is it used often in projects?
Thank you