Interface A=new ClassA();
a.hello();
ClassA, ClassA implements an interface Interface
If I do not have a ClassA with ClassB, so I want to change one ,
If SPRING to achieve, but also to change a configuration
I ask SPRING What is the use of dependency injection ? Advantages
how to reflect spring, dependency injection
Can you give some examples
------ Solution ------------------------------- -------------
if it is dependency injection.
here would not have this new ClassA object. And by the spring dynamically injected into it.
Interface A = new ClassA ();
a.hello ();
changed
Interface A;
a.hello ();
When you need to inject ClassA ClassA object is an object , the object will inject needed ClassB ClassB ( of course ClassB must implement the same interface ) .
So do not repeat this kind of modification. Here spring reflects a decoupling .
------ Solution ---------------------------------------- ----
reform program need to be recompiled , the compiler does not need to change the configuration
dependency injection, the code can not explicitly call new ( new frame automatically help you then injected ) , so that the program does not rely on fixed ClassA, ClassA making procedures and decoupling , so you can not modify the program under the circumstances, to inject other programs to achieve other functions such as ClassB
------ Solution ------------------------------------ --------
you do not know what I mean , modify classB, classB itself to compile , but the program does not need to compile calls classB
is
Interface A = new ClassA ();
a.hello (); This program does not need to compile
If you do not want to configure , you can write a program using annotation (@ annotation ) the way the code , but this is also dependent on words written in code , as low- profile couple , but it is more efficient for developers (do not care about the configuration file )
------ Solution ------------------------------------ --------
with spring, as I understand it , the biggest benefit is to reduce the coupling , not only to modify the file or need to compile problems.
about the landlord said spring eventually going to create the object. But by spring part just to manage , so we freed up , we do not consider writing code to create and manage such objects , the complexity of this part to the spring. Naturally, this is the spring with the benefits .
Of course, what has its advantages and disadvantages of using actual project spring if not bring much convenience , nature can not be used.
------ Solution ---------------------------------------- ----
recommend facie design Patterns: oriented programming interface .
------ Solution ---------------------------------------- ----
so to speak , in a business class, if you want to use to ClassA, ClassA is not an object to be new ? This would be tantamount to business class initiative to create an object . After a reference to spring, how to handle it ? This business is in need of a ClassA class object, the spring IOC container to create the ClassA object, and then injected into the local business class needs . Here reflects the inversion of control mean. ClassA object that is created by the business class of this initiative to create a passive acceptance to inject spring IOC container. This is decoupled .
landlord do not understand , I have no other way .
------ Solution ---------------------------------------- ----
ah , if you are so understanding coupled words.
------ For reference only -------------------------------------- -
this case only if you do not change classA, classB,
and constantly switching between the two rounds of the advantages of using only when
If you want to modify classB, or to compile ,
not write new, but still inside the frame configuration, or no advantage
------ For reference only ------------------ ---------------------
not need to compile this advantage to understand,
but it seems not very obvious advantages , why do so many people use SPRING, dependency injection
And with annotation, annotation errors occur it
------ For reference only ------------------------- -------------- a benefit
with dependency injection is less of a need for dependency a B a and B is just not the case will be multiple dependencies from
------ For reference only --------------------------------------- < br>
did not understand what you say , or at least a dependency what use
And it just does not depend on A or B, but it is dependent on the configuration file , no less dependency
------ For reference only -------------- -------------------------
I know the advantage of reducing the coupling spring , but I do not know how he reduced the coupling
I also know that spring is not the object of our management , but in the end you want to create an object , the advantage is not obvious
You did not say that the point is not just what are the advantages , and more importantly, how to realize the advantages of
------ For reference only -------------- -------------------------
but still need class A class B, there are still coupled , I think just changing the injection the coupling ,
------ For reference only ---------------------------------- -----
spring really no use, you use the xml decoupling , but in xml and generate new coupling system are also dependent xml file , outweigh the benefits.
------ For reference only -------------------------------------- -
seemingly have no idea when it comes to the
1, if you have a 100 program uses new ClassA (); you will understand, a business class in response to the current time special handling requirements , the use of new implementation this month ClassB achieved again after this month in exchange for the original ClassA achieved. Project Manager arrange for you to change, you do not bother ?
2, using the Ioc, provide the basis for the Spring container-managed bean to continue to use other components spring.
sum up : there is no advantage on small projects, complex business advantages.
personal advice , beginners do not use Spring , and it is no longer a lightweight development framework.
What needs to achieve their own right, the realization of a simple dependency injection does not require much time .
------ For reference only -------------------------------------- -
seemingly have no idea when it comes to the
1, if you have a 100 program uses new ClassA (); you will understand, a business class in response to the current time special handling requirements , the use of new implementation this month ClassB achieved again after this month in exchange for the original ClassA achieved. Project Manager arrange for you to change, you do not bother ?
2, using the Ioc, provide the basis for the Spring container-managed bean to continue to use other components spring.
sum up : there is no advantage on small projects, complex business advantages.
personal advice , beginners do not use Spring , and it is no longer a lightweight development framework.
What needs to achieve their own right, the realization of a simple dependency injection does not require much time .
upstairs positive solution ! For dependency injection advantage I have puzzled for a long time

------ For reference only ---------------------------------------
summary, the factory model You can complete explosion dependency injection ...
------ For reference only ------------------------------ ---------
seemingly have no idea when it comes to the
1, if you have a 100 program uses new ClassA (); you will understand, a business class in response to the current time special handling requirements , the use of new implementation this month ClassB achieved again after this month in exchange for the original ClassA achieved. Project Manager arrange for you to change, you do not bother ?
2, using the Ioc, provide the basis for the Spring container-managed bean to continue to use other components spring.
sum up : there is no advantage on small projects, complex business advantages.
personal advice , beginners do not use Spring , and it is no longer a lightweight development framework.
What needs to achieve their own right, the realization of a simple dependency injection does not require much time .
+1
------ For reference only -------------------------------- -------
15L said it right
------ For reference only ----------------------- ----------------
seemingly have no idea when it comes to the
1, if you have a 100 program uses new ClassA (); you will understand, a business class in response to the current time special handling requirements , the use of new implementation this month ClassB achieved again after this month in exchange for the original ClassA achieved. Project Manager arrange for you to change, you do not bother ?
2, using the Ioc, provide the basis for the Spring container-managed bean to continue to use other components spring.
I can modify this does not classA modified to achieve the purpose of the whole
没有评论:
发表评论