royksoft
1 month ago
218
3
General

Alternative to "new up” objects in other objects

Posted 1 month ago by royksoft

I'm a new developer just getting started with testing.

I see in a lot of places that it's a code smell to "new up” objects in other objects.

I'm wondering what are the alternatives. Logically I can use dependency injection, but that requires that I new up the object in the level above, which is probably also in another object.

Are controllers (being the "top of the tree") the only places that should I should instantiate object to keep things unit-testable?

Could any folk share some googlable jargon that will get me a little further towards understanding.

Thanks!

Please sign in or create an account to participate in this conversation.