Einzelnen Beitrag anzeigen

Benutzerbild von DP News-Robot
DP News-Robot

Registriert seit: 4. Jun 2010
15.767 Beiträge
 
#1

When to pass a dependency to a class?

  Alt 12. Mär 2025, 13:20
I was speaking to another developer the other day and he insisted that if a class needs an instance of another class it should always be passed in an 'Init' method and not in the constructor. I disagreed with him on this and thought I should clarify when I think a dependency should be passed.

There are 2 options when passing a dependency to a class:



<ol style="text-align: left;">Passing it as a parameter in the Create constructor.
Passing it in a separate 'Init' method after c

Weiterlesen...
  Mit Zitat antworten Zitat