• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Spring dependency injection

 
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I implemented a small spring dependency injection program and I have one question. Can spring dependency injection be achieved without using interfaces at all (Not having any interface in ya spring application)?? I think the answer is NO. Just wanted to know if I am right or wrong. what do you guys say?/

Thanks.
 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try it?
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Practically speaking, I do not think not using interfaces would hamper dependency injection in spring. I feel it is more of a design issue.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, one of the most common use of DI is to easily switch from ClassBImpl1 to ClassBImpl2 ... to ClassBMock.
This relies on the fact that a common handler (let say 'interface' in Java) can be used to manipulate these different class B implementations.

Technically, you can do it without a common interface.
If your class A has a class B instance variable, defined like this :



you'll have however some difficulties to switch to a mock implementation just through configuration. You'll need to change your class A code to the following :



and ensure that this specific implementation provide the same contract that was offered by ClassBImpl1 (or change the corresponding code).

Using a ClassB interface allows you to change the implementation dependencies with no code modification, relying on the public contract.
 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perfect Christian. Yes I tried it John. Thanks for replying guys.
[ December 07, 2008: Message edited by: Arjun Reddy ]
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic