Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The above comments are correct, but here I am going add some example that helps to you.</p> <p>Look We have 100 Classes that uses <code>UserDao</code> class, And you get dao instance like that: <code>private UserDao userDao = new UserDaoImpl();</code> in 100 places, </p> <p>After few weeks the requirement changed and we need to use <code>LdapUserDao</code> or something similar </p> <pre><code>class LdapUserDao implements UserDao{ } </code></pre> <p>that implements <code>UserDao</code>. What do you do? How do you handle your <code>new</code> keywords, You tied impl class into usage. </p> <p>If you use @Autowired in 100 places then from one place (if you use xml based config then, just go xml and switch to another UserDao from xml, if annotation the go to that component and switch Spring annotation to proper one) manage it, so in 100 places it appears. This is what is called <code>DI</code> pattern. This is whole purpose of <a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="nofollow">DI</a></p> <p>Another important thing is with spring annotation even you can manage object scope, but with new keyword no way(unles you do dumb singleton or something like that), I am sure with new keyword you can no have</p> <pre><code> Prototype Request Single </code></pre> <p>Scoped objects</p> <p>In terms of performance, It is quite difficult to say, unless to see your code. But I am sure at worst case they may have equal performance, otherwise springs way is fast, because As I know dao class should be singleton, not prototype, so whole project you will have on userdao object in spring way, with <code>new</code> way It depends where you are loosing reference to dao object. But Leave the performance. Do not consider performance over good design. All time 1st make it in good manner(not fast manner) with good design, then look it's performance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload