It may be a simple question that I am currently learning Spring Framework and Dependency Injection D It is not easy to understand the basic principle of, but it is not immediately clear why you need a broad framework to implement it.
Consider the following:
viewed the public essence class (public essence zero cut (string wood);} in the hands of public class (public string wood) ( Public string wood extension [// cut it]} Public square Chansaw saw [public Zero reduction] (// it cut very fast}} Public square SAWMIL {Private seen seen; Public Zero Set (see seen) {This saw saw =;} abstract Public Zero Run (string wood) {saw.cut ("some wood");}}
Then you could just do that:
looked = New Hand (); SawMill Saw Mile = New SawMill (); sawMill.setSaw (seen); sawMill.run ();
Which would be equivalent to:
& lt; bean id = "saw" square = "handsaw" /> gt; bean id = "saw mile" square = "join"> gt; property name = "saw" riff = "Seen" />
plus:
applicationcontact reference = new classpath XML application context ("Sommil. XML"); SAWMill Spring SawMill = (SawMill) context.getBean ("sawMill"); SpringSawMill.run ();
This is an example example, with more complex object relationships, it can be more efficient to hide XML files by writing a program to a program, but of course its Should be more for that
(I know that the Spring Framework is more than that, but I am thinking of the need for a DI detector.)
In the first example it will be trivial between dependency To make changes in:
// It will be cut as soon as possible = new chainsaw (); SawMill.setSaw (seen); SawMill.run (); I have the exact same question, and it has answered:
br> Dixit, whatever you described as "you could just do ... ..." (let's say "class A"). However, for all dependencies required from Class Ato Handsaw or Class Simil Why should be added for the handshaw - or, if you take a more realistic scenario, then why should my business logic be linked to the necessary JDBC connection implementation for the DAO layer?
The proposed solution which I had proposed, then "Move forward the dependence one step ahead" - OK, so now I have got my idea with the JDBC connection, where I should only deal with HTML (or swing) , Should take your taste).
The D-Framework, which resolves by giving an XML (or JavaConfig) "get the necessary service" to you.
In addition, you have a misconception about "plus:" (where you are Sommil Spring SawMill = (SawMill) context.getBean ("sawMill"); Spring SawMill.run ();
) - You do not need to get the bean from the context - the verb bean should be had injected into your object (class A) by the framework, so ... about ... BBAN (...), you'll just see "Mill Miller", not where he came from, who started it and Kiss Has been from the beginning. To take care of all of you, it can go straight to / dev / null, or test production, or actual CNC engine ... The issue is - you do not care. Take care of all of your small class A, which should be contracted to do this - activate a get mill.
Comments
Post a Comment