Home > Software engineering >  Is Spring more suitable for business-logic-focused apps?
Is Spring more suitable for business-logic-focused apps?

Time:12-17

After reading the official doc of Spring, I got this impression:

"Spring, specifically its IoC container, suits better for apps that requires only one instance of most classes".

For example we have an online shopping app. Its business logic is divided into

  • Order process
  • Payment process

and encapsulating these two parts into classes is for better code organisation rather than for implementing any functionalities, and Spring makes it easier to inject the same instance to whichever object needs it, to avoid frequent and redundant new.

However, in a Mario-like game, we might have a class Coin that requires hundreds of individual instances, and hence Spring can't be applied in this case ('cause I think @qualifier makes more mess than the good part brought by IoC).

Is the above correct?

CodePudding user response:

You're correct in thinking that you wouldn't inject an object that only applies in a narrow scope.

I could see objects with Request scope that are not Singleton. Spring has supported that from the beginning.

Method scope variables should not be under Spring's control. There's nothing wrong with calling new.

You should understand Spring better before you make judgements about its efficacy.

  • Related