java - API design: one generic interface VS three specialized interfaces? -
java - API design: one generic interface VS three specialized interfaces? -
i'm working on tool users can utilize own annotations describe info processing workflow (like validation, transformation etc).
besides using ready-to-use annotations, users can user own: in order need declare annotation class itself, , implement annotation processor (<--it's main point of question actualy).
the configured method info processing may one:
void foo(@provide("dataid") @validate(validator.class) string str) { dosmth(str); } there're naturally 3 groups of annotations:
those produce initial values; those transforms values (converters); those read values , perform work (validators, different consumers).so need create choise: either create 1 interface handling these types of annotations, can one:
interface genericannotationprocessor { object processannotation(annotation annotation, object processedvalue); } or can add together 3 intefaces api:
interface producerannotationprocessor { object produceinitvalue(annotation annotation); } interface transformerannotationprocessor { object transformvalue(annotation annotation, object currentvalue); } interface consumerannotationprocessor { void consumevalue(annotation annotation, object currentvalue); } the first alternative not clear in use, 3rd alternative pollutes api 3 similar interfaces.
what take (first of api user) , why?
thanks!
i create first, more general interface, define 3 different implementation classes. without knowing more how using this, first instinct define interface and/or base of operations class (depending upon how much mutual implementation code shared between different processors), , add together specialized processor implementation in derived types, of whihc share mutual interface.
in using api, expect declare variable implements genericannotationprocessor, , assign appropriate implementation type depending upon needs.
it here in portland, or, @ moment, @ 50% of required caffeine level, seems me provide maximum flexibility while maximizing cade re-use.
of course, actual reuirements might dictate otherwise . . .
hope helpful!
java oop interface api-design
Comments
Post a Comment