In the source code I'm evaluating (jarjar), there exists java code that can be used like this:
JarJarTask fixture = new JarJarTask(); fixture.addConfiguredRule(new Rule()); fixture.execute();
Which will throw an exception like:
java.lang.IllegalArgumentException: The <rule> element requires both "pattern" and "result" attributes.
Now, to me it is clear that the API is less than optimal here - if the rule element requires these attributes, it should ask for them in the constructor (or provide a Builder or similar that would require them). But I was unable to find coding conventions or java programming recommendations to agree with me.
Is there some specific name for this that I can use to look this up in research, programming literature, style guides? Which terms could I use to find some discussion on this?
Surely it's been discussed somewhere using some terms, but I seem to be unable to find anything.
I did find discussion around constructor injection as presented by Kent Beck in Smalltalk Best Practice Patterns and supported by Martin Fowler, which, according to this, makes it "immediately clear what a class requires when it is instantiated, and furthermore it is impossible to instantiate the class without passing in the field’s objects". So that's a starting point at least to find some discussion.