I got a little lost here because I want to do something very simple in Java, but it seems a bit complicated in PHP.
We are building the SDK for our product and in Java, we have this one class that should not (!) Be created by the user (i.e. the encoder), since there are several integrity restrictions. So we built it as a nested class “X” inside “XFactory”, and you get an instance of X by calling XFactory.buildMeMyX (); - Easy...
Now PHP does not support nested classes at all, and I am wondering how to apply this here. In Java, the X constructor is hidden (private), so only XFactory can call it.
In PHP, it seems I will have to make __construct () public and move the nested X class from XFactory. Consequently, the user will be able to create an instance without Factory.
Now - you CAN move the factory functionality to X itself and move all things there, but this will partially break the SDK design. Is there a useful way to do such things in PHP after all?
source
share