What's forcing you to expose StatefulClass' constructor?  Why not provide a
factory for StatefulClass as well?


On Mon, Sep 14, 2009 at 11:38 PM, Gili <[email protected]> wrote:

>
> Hi,
>
> A few months ago I asked whether one should expose Guice in public
> APIs or hide it. I was advised to use Guice under the hood (to improve
> testability) and expose factory classes to end-users. Here is what
> I've got so far:
>
>
> /** For internal use */
> class StatelessClass
> {
>  @Inject
>  public StatelessClass(OtherClass other);
>
>  public Integer toInteger(String text);
> }
>
> /** For end-users */
> class StatelessClassFactory
> {
>  public static StatelessClass getInstance();
> }
>
> /** For end-users */
> class StatefulClass
> {
>  public StatefulClass(String arg1, String arg2);
>
>  public doSomething();
> }
>
>     So users instantiate StatelessClass using
> StatelessClassFactory.getInstance() which uses an Injector under the
> hood. They use "new StatefulClass()" to get an instance of
> StatefulClass. But then what happens if StatefulClass needs to
> reference StatelessClass? If I use StatelessClassFactory it makes
> StatefulClass harder to unit-test, but what's the alternative?
>
> Thanks,
> Gili
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to