Factory Reverse design pattern discussion

29 Views Asked by At

I used to use factory method as a creational design pattern, but now I got stucked in the situation which is reversing the problem. The normal behavior to create the factory pattern. I am facing the following: I got different inputs for the same data object. I create a function that set the data to the object based on the passed data like the following:

public function __construct(array|Ad $data){
    match(getType($data)){
        'array' => $this->setFromArray($data),
        default => $this->setFromSnapAdModel($data)
    };
}

Is that looking right or not? Is that pattern that I face in my code is looking like reversing the factory creational method?

0

There are 0 best solutions below