Can I force the user to either:
class CustomBar extends Bar
or:
CustomFoo implements IFoo ?
They can't avoid it. Let's look at them in turn:
In order to provide an instance of Bar
to your framework, they have to create the instance. But Bar
cannot be instantiated, it's an abstract class (you declared it as abstract class Bar
). To create an instance, you have to subclass it and then create an instance of the subclass.
Similarly, IFoo
is an interface. You can't instantiate an interface. To create an instance that uses the interface, you have to define a class that implements the interface, then create an instance of that class.
Absolutely you want to document things as well, but by making the classes abstract
and using interfaces, you're forcing them to subclass/implement if they ever want to create instances to pass into your framework.