I am developing a package for the Unity game engine. I want to add additional functionality to my package if another specific package is present. I am faced with a dilemma I am not sure which of these two options is better in terms of API design and usability.
While not frequent, one can expect users to swap between having the other package installed or not. It would also be a fair assumption to say yet another third package might use my package as a dependency.
Thank you in advance for your thoughts and suggestions.
1. Stub values and exceptions
This option would mean the public API of my package won't change based on whether or not the user has the other package installed, but the values they would get would either be stubs or throw exceptions. Example:
public bool FooBar =>
#if OTHER_LIB_PRESENT
OtherLib.Value();
#else
false; // or throw an exception
#endif
2. Public API change
This option means the public API of my package would change depending on whether or not the user has the other package installed. Example:
#if OTHER_LIB_PRESENT
public bool FooBar => OtherLib.Value();
#endif
other_lib
condition) is present then it is almost a guarantee that the conditional features will be desired by the user, because they are very much interconnected.OtherLib.Value()
; if it's not it doesn't. And if it's set but they don't haveOtherLib
installed, an exception naturally gets thrown (ModuleNotFoundException
or something like that)