|
26 | 26 | import com.google.inject.Injector; |
27 | 27 |
|
28 | 28 | /** |
29 | | - * |
30 | 29 | * Dependency Injection pattern deals with how objects handle their dependencies. The pattern |
31 | 30 | * implements so called inversion of control principle. Inversion of control has two specific rules: |
32 | 31 | * - High-level modules should not depend on low-level modules. Both should depend on abstractions. |
|
45 | 44 | * The fourth example takes the pattern a step further. It uses Guice framework for Dependency |
46 | 45 | * Injection. {@link TobaccoModule} binds a concrete implementation to abstraction. Injector is then |
47 | 46 | * used to create {@link GuiceWizard} object with correct dependencies. |
48 | | - * |
49 | 47 | */ |
50 | 48 | public class App { |
51 | 49 |
|
52 | | - /** |
53 | | - * Program entry point |
54 | | - * |
55 | | - * @param args command line args |
56 | | - */ |
57 | | - public static void main(String[] args) { |
58 | | - SimpleWizard simpleWizard = new SimpleWizard(); |
59 | | - simpleWizard.smoke(); |
| 50 | + /** |
| 51 | + * Program entry point |
| 52 | + * |
| 53 | + * @param args command line args |
| 54 | + */ |
| 55 | + public static void main(String[] args) { |
| 56 | + SimpleWizard simpleWizard = new SimpleWizard(); |
| 57 | + simpleWizard.smoke(); |
60 | 58 |
|
61 | | - AdvancedWizard advancedWizard = new AdvancedWizard(new SecondBreakfastTobacco()); |
62 | | - advancedWizard.smoke(); |
| 59 | + AdvancedWizard advancedWizard = new AdvancedWizard(new SecondBreakfastTobacco()); |
| 60 | + advancedWizard.smoke(); |
63 | 61 |
|
64 | | - AdvancedSorceress advancedSorceress = new AdvancedSorceress(); |
65 | | - advancedSorceress.setTobacco(new SecondBreakfastTobacco()); |
66 | | - advancedSorceress.smoke(); |
| 62 | + AdvancedSorceress advancedSorceress = new AdvancedSorceress(); |
| 63 | + advancedSorceress.setTobacco(new SecondBreakfastTobacco()); |
| 64 | + advancedSorceress.smoke(); |
67 | 65 |
|
68 | | - Injector injector = Guice.createInjector(new TobaccoModule()); |
69 | | - GuiceWizard guiceWizard = injector.getInstance(GuiceWizard.class); |
70 | | - guiceWizard.smoke(); |
71 | | - } |
| 66 | + Injector injector = Guice.createInjector(new TobaccoModule()); |
| 67 | + GuiceWizard guiceWizard = injector.getInstance(GuiceWizard.class); |
| 68 | + guiceWizard.smoke(); |
| 69 | + } |
72 | 70 | } |
0 commit comments