I'm having trouble understanding/linking the code example to the diagram and definition for the Factory Pattern.
abstract class Shape { ... }
class Rectangle extends Shape { ... }
class Triangle extends Shape { ... }
abstract class ShapeFactory {
static function Create($type, array $sizes) {
switch ($type) {
case 'rectangle':
return new Rectangle($sizes[0], $sizes[1]);
break;
case 'triangle':
return new Triangle($sizes[0], $sizes[1], $sizes[2]);
break;
}
}
}
$obj = ShapeFactory::Create($_GET['shape'], $_GET['dimensions']);
Must be having an off day because I'm not seeing how the abstract factory class is being extended in the code example.
I was unable to find any information in the book explaining the solid arrows or the term concrete, can anyone point me to the right pages, I must be going blind :/
Any help greatly appreciated.
edit: ok I think I understand why there was confusion. The UML diagram used in the book is representative of the second reason/example given for using the factory pattern (where a base factory class is extended) but the code example references the first reason given for using a factory class and there is no UML diagram for this.