Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Spring Framework & interfaces  RSS feed

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I am new to Spring Framework and hence this question.

Is it always necessary to create Interfaces and implementation classes in order to take advantage of Inversion Of Control?

Thanks,
Kunal
 
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not Spring authority but no, I don't think so.
Creating interfaces and implementing classes is a best practice/
 
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Todd wrote:I'm not Spring authority but no, I don't think so.
Creating interfaces and implementing classes is a best practice/



If you want to configure transactions or AOP or other integrations that causes Spring to create a Proxy, then it will need an interface for the real object as it uses DynamicProxies to create those proxies. You can still not have an interface, but you have to add a configuration to those beans to use CGLib and generate proxies by subclassing the real class you want to make a proxy for.

Mark
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use IoC without using interfaces. Anyway, when doing object-oriented whether you're using IoC or not, you should have interfaces to make the design flexible and easy to understand.
 
Greenhorn
Posts: 8
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and it makes Unit-testing easier.
 
Kunal Sathe
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks folks!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!