java - Interface with inner implementation - good or bad -
i working on project many someinterface - someinterfaceimpl-pairs. days ago got idea (probably inspired reading objective c code) include default implementations inner class. colleagues (all more java experience me) saw idea - feedback between shocked , surprised ("this working?").
i googled around bit didn't find evidence of usefulness of "pattern" (personal it): pdf-paper , a faq code style
what think - in cases "default" implementation tightly coupled interface.
update found this: java interface-implementation pair
(see accepted answer)
the whole point of interfaces separate users implementation (default or not). defeat including implementation inner class. don't save lines of code , clutter api. end having things hide inner class users of interface making private or default scope might better avoid. also, if default implementation needs change have published interface part of api. bad idea in not have lot of benefit , anti-pattern.
finally, if have default implementation maybe should base class (rather interface) , other implementation extend class , override behavior.
i thought post gives interesting discussion of similar question: question
Comments
Post a Comment