mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-13 12:14:51 +00:00
docs: update dependency injection
This commit is contained in:
1 parent
c1466eb66e
commit
0b850aa764
6 files changed
+68
-38
No files matched your search
@@ -28,7 +28,7 @@ import com.google.inject.Guice;
|
||||
|
||||
/**
|
||||
* Dependency Injection pattern deals with how objects handle their dependencies. The pattern
|
||||
* implements so called inversion of control principle. Inversion of control has two specific rules:
|
||||
* implements so-called inversion of control principle. Inversion of control has two specific rules:
|
||||
* - High-level modules should not depend on low-level modules. Both should depend on abstractions.
|
||||
* - Abstractions should not depend on details. Details should depend on abstractions.
|
||||
*
|
||||
@@ -37,7 +37,7 @@ import com.google.inject.Guice;
|
||||
* concrete implementation which cannot be changed.
|
||||
*
|
||||
* <p>The second and third wizards({@link AdvancedWizard} and {@link AdvancedSorceress}) are more
|
||||
* flexible. They do not depend on any concrete implementation but abstraction. They utilizes
|
||||
* flexible. They do not depend on any concrete implementation but abstraction. They utilize
|
||||
* Dependency Injection pattern allowing their {@link Tobacco} dependency to be injected through
|
||||
* constructor ({@link AdvancedWizard}) or setter ({@link AdvancedSorceress}). This way, handling
|
||||
* the dependency is no longer the wizard's responsibility. It is resolved outside the wizard
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ class AdvancedSorceressTest {
|
||||
* her through the setter's parameter
|
||||
*/
|
||||
@Test
|
||||
void testSmokeEveryThing() throws Exception {
|
||||
void testSmokeEveryThing() {
|
||||
|
||||
List<Tobacco> tobaccos = List.of(
|
||||
new OldTobyTobacco(),
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ class AdvancedWizardTest {
|
||||
* through the constructor parameter
|
||||
*/
|
||||
@Test
|
||||
void testSmokeEveryThing() throws Exception {
|
||||
void testSmokeEveryThing() {
|
||||
|
||||
List<Tobacco> tobaccos = List.of(
|
||||
new OldTobyTobacco(),
|
||||
|
||||
@@ -35,7 +35,6 @@ class AppTest {
|
||||
|
||||
/**
|
||||
* Issue: Add at least one assertion to this test case.
|
||||
*
|
||||
* Solution: Inserted assertion to check whether the execution of the main method in {@link App#main(String[])}
|
||||
* throws an exception.
|
||||
*/
|
||||
|
||||
+2
-2
@@ -58,7 +58,7 @@ class GuiceWizardTest {
|
||||
* through the constructor parameter
|
||||
*/
|
||||
@Test
|
||||
void testSmokeEveryThingThroughConstructor() throws Exception {
|
||||
void testSmokeEveryThingThroughConstructor() {
|
||||
|
||||
List<Tobacco> tobaccos = List.of(
|
||||
new OldTobyTobacco(),
|
||||
@@ -83,7 +83,7 @@ class GuiceWizardTest {
|
||||
* through the Guice google inject framework
|
||||
*/
|
||||
@Test
|
||||
void testSmokeEveryThingThroughInjectionFramework() throws Exception {
|
||||
void testSmokeEveryThingThroughInjectionFramework() {
|
||||
|
||||
List<Class<? extends Tobacco>> tobaccos = List.of(
|
||||
OldTobyTobacco.class,
|
||||
|
||||
Reference in new issue
Block a user