• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

bean relationship

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my java classes, I have some relationship like

class A {

private B b;
private C c;

}

class B {

private C c;

}

class C {

private String name;
...
}

Then in the <bean> definition it will be like

<bean id="c" class="C">
<property name="name" value="xxxx"/>
</bean>

<bean id="b" class="B">
<property name="c" ref="c"/>
</bean>

<bean id="a" class="A">
<property name="b" ref="b"/>
<propery name="c" ref="c"/>
</bean>


Is this a good and reasonable design in Spring ? Does this work ?
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben,
It looks fine. Assuming you have the relevant setters of course. (I understand you left them out for brevity; just mentioning in case someone takes the example literally.)

You don't have anything complex like a circular dependency. The only "wrinkle" I can think of is that you get the same instance of C injected into A and B unless you specify otherwise. Of course most of the time, having the same instance is fine.
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic