View Single Post
Old 10-10-2012, 06:19 PM   PM User | #1
Oatley
New Coder

 
Join Date: Sep 2012
Posts: 69
Thanks: 56
Thanked 0 Times in 0 Posts
Oatley is an unknown quantity at this point
Factory design pattern?

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

Last edited by Oatley; 10-10-2012 at 06:21 PM..
Oatley is offline   Reply With Quote