Hi Jordi,

Thanks for the response -- I think you've helped refine my questions:

- When is a new better than an inject?
   ... and I guess your saying is that value objects (that may have a
large cardinality in the system)
   ... are poor uses for an injection ... thoughts?

Thanks,

Bubba.



On May 11, 7:05 am, jordi <[email protected]> wrote:
> In case you really need to inject value classes, Guice does that for you
> for free. If you @Inject a Person (non-scoped), every time will give a new
> Person.
>
> But I can't figure out why a simple value class should be managed by Guice.
> In this case I'm sure that's easier and clearer to just use a regular,
> old-fashioned new.
>
> If what you're looking for is to inject a Service in conjunction with some
> value class, take a look at Assisted Inject [1]
>
> hth,
> jordi
>
> [1]http://code.google.com/p/google-guice/wiki/AssistedInject
>
>
>
>
>
>
>
> On Thu, May 10, 2012 at 10:45 PM, Bubba 42 <[email protected]> wrote:
> > Hi,
>
> > I've been unable to find a suitable answer to this question.
>
> > If I understand this correctly: Dependency Injection can be used to
> > instantiate service objects -- object that essentially abstract away
> > some computational service ... for example (an instance of this class
> > would essentially be stateless, save for resources that it might be
> > plugged into such as SimpleMath.properties, and I would expect that
> > there would be small number of instances of this class per application
> > instance say under 5):
>
> > class SimpleMath {
>
> >  public int addTwoNumbers (int n1, int n2) {
> >    return n1 + n2;
> >  }
>
> >  public int multiplyTwoNumbers (int n1, int n2) {
> >    return n1 * n2;
> >  }
>
> > }
>
> > Now can DI be used to instantiate value objects (for the lack of a
> > better word). By a value object I mean an object that has state and
> > the methods are impacted by that state, for example (as opposed to the
> > previous class I would expect there to be hundreds or thousands of
> > instances of this class):
>
> > class Person {
>
> >  int age;
> >  int weight;
> >  String fname;
> >  String lname;
> >  // and so on
>
> >  public String hail() {
> >    return "Hello to you to, I am " + fname + " " + lname;
> >  }
>
> >  public String howOldAreYou() {
> >    return "I don't really like talking about my age but I'm " + age +
> > " years young";
> >  }
>
> >  // and so on
>
> > }
>
> > Thanks.
>
> > --
> > 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.

-- 
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