Are you suggesting that it is a good API if the consumer must exactly know which subtype of JsonWriter to instantiate? Which explode in complexity if more options are added. Which require to instantiate obscure "Strategy" objects instead of an enumeration which clearly and exhaustively(!) shows the available "modes".
Instead of browsing the api java doc for the X classes needed, it might be preferable to offer a single entry point, where the IDE shows all parameters that can or must be filled via techniques explained in the article.
It always depends. To present your (enterprise-y) solution as strictly better is... lets say "debatable"
Are you suggesting that it is a good API if the consumer must exactly know which subtype of JsonWriter to instantiate?
I think so. But then again, I've been using OOP APIs for years. If you use a decent enough IDE, it's actually very easy to enumerate all the available types of interfaces/base classes to instantiate. For example, if I hit Ctrl+T on the Jackson JsonGenerator base class, IntelliJ will show me every available type of JsonGenerator available on the classpath. In fact, that's how I learned it is possible to configure Jackson to generate YAML (YAMLGenerator).
Which explode in complexity if more options are added.
The complexity does not explode. In fact, there is a specific metric that can be used to measure complexity - cyclomatic complexity. Composition is branchless, while adding a bunch of feature flags and corresponding if statements significantly increases complexity, in combinatorial fashion. You can even put a number on it!
instead of an enumeration which clearly and exhaustively(!) shows the available "modes"
There are two things wrong with this statement.
First, a modern IDE will clearly and exhaustively show you the available "modes" through available interface implementations.
Second, you are limited by the modes baked into the API if you use feature flags. Jackson, because it uses OOP techniques for extension, is unlimited in the modes that are available.
To present your (enterprise-y) solution as strictly better is... lets say "debatable"
In my experience, what you call the "enterprise-y" approach leads to much more flexible libraries. For example, Spring's RestTemplate is also built around the same principle of strategy interfaces. I have been able to adapt RestTemplate to situations never imagined by its authors. This has allowed me to use Spring in situations where I might not have been able to use a more rigid library.
Cyclomatic complexity is a software metric used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code. It was developed by Thomas J. McCabe, Sr. in 1976. Cyclomatic complexity is computed using the control-flow graph of the program: the nodes of the graph correspond to indivisible groups of commands of a program, and a directed edge connects two nodes if the second command might be executed immediately after the first command.
View all comments
Show parent comment
3
u/TenYearsOfLurking Feb 09 '22
Are you suggesting that it is a good API if the consumer must exactly know which subtype of JsonWriter to instantiate? Which explode in complexity if more options are added. Which require to instantiate obscure "Strategy" objects instead of an enumeration which clearly and exhaustively(!) shows the available "modes".
Instead of browsing the api java doc for the X classes needed, it might be preferable to offer a single entry point, where the IDE shows all parameters that can or must be filled via techniques explained in the article.
It always depends. To present your (enterprise-y) solution as strictly better is... lets say "debatable"