That is the scenario of the interface Vs. the abstract class
scenario 1: The third party implement the interface provided by me, then register it on my system.I would invoke it's method(s).
scenario 2: The third party implement the child class which extends the abstract class defined by me,
then i create the new child class instance. But how can i learn the child class constructor?
So i would restrict the child class constructor.
Thanks.
Well, I think it's useless to try to force the class to have a no-arg constructor. You might write it in the specifications that they are required to provide one, but trying to use AOP to achieve that is a bad idea.
So what if they don't provide a no-arg constructor? Then their class won't work. If they want it to work, they provide the no-arg constructor.
That's it. You're not supposed to make things idiot proof.
Yes, and factory method is out of the question since it would need to be static and you can't force a static method more than you can force a constructor.
But the bottom line is, provide the specs for the interface and that's it.
If your program does weird trickery to get malformed classes to work with the interface, that's not very good.