Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why interfaces are light weight when working on spring fram work

 
ehsan ulhaq dar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While using spring it is said that while write your classes it is good to use interfaces whether it is model class, or it is controller class or it is service class because when we use interface the application will be light weight. Can anybody explain why application is light weight when using interfaces.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ehsan ulhaq dar wrote:While using spring it is said that while write your classes it is good to use interfaces whether it is model class, or it is controller class or it is service class because when we use interface the application will be light weight. Can anybody explain why application is light weight when using interfaces.


Not really lightweight as code has no physical weight in LBS. ;)

Anyway, coding to an interface has so many advantages regardless of whether it is in the context of Spring. With coding to an interface you can easily swap out any implementation without having to change code. You just write another implementation and use it instead. Coding to an interface helps make your code looser coupled which is a big thing when you have to change things. Everything always changes, so if you are tightly coupled, it makes changes really difficult and makes you take more time to code to do those changes. Also with interfaces help with Unit Testing so you can mock or stub out a dependency via its interface.

Interfaces also allows for DynamicProxies to be created in which you can add so much more functionality to your code without changing your code itself. AOP uses this.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic