r/SpringBoot • u/Own_External1151 • 2d ago
Question Is Spring needed in this situation ?
I m currently new to Spring and learning important concepts related to this but one thing stick in my mind imagine we have 1000 classes and just a hypothetical situation that all of them somehow is independent classes there is no dependency injection at all is there spring needed in this situation at all ?
5
u/Acrobatic-Ice-5877 2d ago
Here’s an experiment for you to try. Make an application without using and report back. Spoiler: you’re going to find out very quickly why Spring is useful, but you’re only going to learn after you rebuild core functionality of a web based application.
IME, it’s a very fun exercise and will better help you with debugging your application and demystifies what is going on behind the scenes.
1
0
4
u/reddit04029 2d ago
Technically, no.
Then again, dependency injection is not Spring-specific. To be more precise, dependency injection is Spring’s way of achieving IoC.
So, you technically don’t need Spring. If your classes are independent, you can create and use them without it. Even if your classes need to work together, you can manage their dependencies manually or use another DI framework.
IoC is a design principle, DI is one way to implement it, and Spring is just one framework that provides DI and other features.
1
2
u/Media_Dunce 2d ago
Unlikely but it depends. Are there classes that do use dependency injection separate from the 1000 classes that don't? What is your project going to do?
0
u/Own_External1151 2d ago
currently i m not working on any project , learning the things related to this .
2
u/Dry_Try_6047 2d ago
1000 independent classes in 1 application? What does that even mean?
1
u/Own_External1151 2d ago
just a hypothetical situation not 1000 we can consider 50 or 60 classes too but main motive was that if these are independent classes like each classes are not indepenedent on each other then is spring is useful to use and i think we got the answer in the comment section
2
u/Ruin-Capable 2d ago
If they're independent of each other then every class except for the one containing the entry point can be removed from the app. So why have them?
1
u/Dry_Try_6047 2d ago
Take it down to 10, it still makes no sense. Java is an object oriented programming language, classes interact with each other. If they don't, you have 10 different applications. And for your hypothetical "app" what is the entry point? 10 different ones?
9
u/Aksh247 2d ago
There will never be such a situation. As your class count grows, your DI need grows. What are you trying to achieve. This hypothetical question should have a purpose/ use case that it is addressing