Skip to main content
added 1 character in body; edited tags
Source Link
  1. showInfo() doesn't need to depend on Student, which can use other types of objects that also contain name and age (eg: Teacher) instead of binding specific implementation

  2. EaserEasier to test : Pass required parameters only doesn't need to new a Student object first to test showInfo(),or we may replace Student with other objects that also has name and age such as Teacher at the calling client side, more likely a unit test instead of integration test

  3. Looser coupling : Removing Student class doesn't require me to modify showInfo() to recompile

  4. More reuseable showInfo() : I don't need to create another showInfo() method when I need another object (eg: I don't need to add

  1. showInfo() doesn't need to depend on Student, which can use other types of objects that also contain name and age (eg: Teacher) instead of binding specific implementation

  2. Easer to test : Pass required parameters only doesn't need to new a Student object first to test showInfo(),or we may replace Student with other objects that also has name and age such as Teacher at the calling client side, more likely a unit test instead of integration test

  3. Looser coupling : Removing Student class doesn't require me to modify showInfo() to recompile

  4. More reuseable showInfo() : I don't need to create another showInfo() method when I need another object (eg: I don't need to add

  1. showInfo() doesn't need to depend on Student, which can use other types of objects that also contain name and age (eg: Teacher) instead of binding specific implementation

  2. Easier to test : Pass required parameters only doesn't need to new a Student object first to test showInfo(),or we may replace Student with other objects that also has name and age such as Teacher at the calling client side, more likely a unit test instead of integration test

  3. Looser coupling : Removing Student class doesn't require me to modify showInfo() to recompile

  4. More reuseable showInfo() : I don't need to create another showInfo() method when I need another object (eg: I don't need to add

Became Hot Network Question
added 21 characters in body
Source Link
  1. "Non dependency injection" has less parameters in the Client constructor, which fits the motivation of "Preserve whole object" that shorter parameter list is better

  2. In "Non dependency injection", adding new components don'tdoesn't need to modify the parameter list ofin constructors,eg:

but the "Dependency injection" version needs to add a new parameter to the constructor:

  1. "Non dependency injection" has less parameters in the Client constructor, which fits the motivation of "Preserve whole object" that shorter parameter list is better

  2. In "Non dependency injection", adding new components don't need to modify the parameter list of constructors,eg:

but the "Dependency injection" version needs to add a new parameter:

  1. "Non dependency injection" has less parameters in the Client constructor, which fits the motivation of "Preserve whole object" that shorter parameter list is better

  2. In "Non dependency injection", adding new components doesn't need to modify the parameter list in constructors,eg:

but the "Dependency injection" version needs to add a new parameter to the constructor:

added 12 characters in body
Source Link

which "Non dependency injection" fits the situation of "preserve whole object is better" that passing "Studnet" instead of "name" and "age" becauseallows us adding new properties don't need to(eg: dateOfBirth) without modify the parameter list

, as if in "preserve whole object" version that showInfo() repeating getterstypes "student" only:

instead of typing getters at each parameter:

which "Non dependency injection" fits the situation that passing "Studnet" instead of "name" and "age" because adding new properties don't need to modify parameter list

, as if in showInfo() repeating getters:

instead of

which "Non dependency injection" fits the situation of "preserve whole object is better" that passing "Studnet" instead of "name" and "age" allows us adding new properties (eg: dateOfBirth) without modify the parameter list

, as if in "preserve whole object" version that showInfo() types "student" only:

instead of typing getters at each parameter:

added 12 characters in body
Source Link
Loading
deleted 5 characters in body
Source Link
Loading
added 165 characters in body
Source Link
Loading
added 165 characters in body
Source Link
Loading
added 12 characters in body
Source Link
Loading
added 90 characters in body
Source Link
Loading
added 172 characters in body
Source Link
Loading
added 4 characters in body
Source Link
Loading
Source Link
Loading