I was going through Effective Java and reading static factory methods for creating objects. Its chapter 2, Item 1. There in the advantage no. 3, the writer has mentioned like
Hiding implementation classes in this fashion can lead to a very compact API. This technique lends itself to interface-based frameworks, where interfaces provide natural return types for static factory methods.
I could not understand what the interface-based frameworks are?
Maybe rephrasing it a bit would help :
an interface-based framework is a framework giving the user/client lib access to interfaces only while actually delivering classes implementing those interfaces.
The benefit of this approach consists in giving the implementor full control over the implementation and giving the client a stable API at the same time.
I encountered an example lately, where the client gets an XmlProcessor
from an API method. Inside the framework, there are three totally different implementation of this processor : a DomXmlProcessor
, SaxXmlProcessor
and a VtdXmlProcessor
. The details of the individual implementations are of no concern to the client and can be switched any time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With