I would not say that you are "mistaken", but there is a "smell". By combining a factory method in an industrial class, the architecture breaks some of SOLID :
- One responsibility: the class now does two things (when it should do it).
- / : ( ).
- : , factory ( ).
, SOLID , . , SOLID , .
, ? , factory , . , , . , :
class ETF {
final public static factory($kind) {
switch ($kind) {
case 'A':
$etf = static::factoryHelperForA();
break;
case 'B':
$etf = static::factoryHelperForA();
break;
}
return $etf;
}
public function apiMethod1() {
$this->apiMethod1Helper();
}
public function apiMethod2() {
$this->apiMethod2Helper();
}
private static function factoryHelperForA() {
}
private static function factoryHelperForB() {
}
private function apiMethod1Helper() {
}
private function apiMethod2Helper() {
}
}
, , , factory , . , SOLID .
, factory EtfFactory.