Reputation: 9082
I have stumbled upon an interesting problem/bug that I eventually solved, but the solution is not what I expected or would like it to be.
The setup is simple. There is an abstract static class Factory, which has a reference to a singleton (Registry) as well as two static properties, model and table.
There are a number of static classes building upon/inheriting from this abstract class and they all have an init() method in which they set the model and table properties. Of course, since model and table are static they can only have one value which is the same for all the child classes of the abstract Factory class. This is the problem/bug.
However, my aim is to have each child class have its own model and table so I am forced to declare model and table in each child class as a static property. This seems a bit cumbersome (and not very DRY), but it seems to me that this is the only solution if I want to have (1) the classes inherit from the abstract Factory class and (2) remain static.
Is my assumption correct or is there another approach that I am missing?
Upvotes: 0
Views: 209
Reputation: 18071
The goal is to have different values for $model
and $table
in different static child classes?
Assuming that is the case, I don't see how You could possibly accomplish that without explicitly defining them different in each child class.
I don't think it is cumbersome. I see it as a good practice - by keeping functionality where it belongs.
Upvotes: 1