Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instance methods Vs Static Methods in the business layer [closed]

I have a typical web application with the controllers calling the business methods. Should the methods in the business classes be implemented using static methods or instance methods. The business layer classes doe not maintain any state information.

Some additional information + The business classes do not maintain state specific information. + Would instantiating these objects on a per request basis consume a lot of memory as opposed to using static methods

like image 778
user3547774 Avatar asked Nov 01 '22 20:11

user3547774


1 Answers

Does "yes" count as an answer? I hate to say it, but both answers are valid; choosing between them requires context. If you have no use for per-instance state, then: why create instances? However, it should be noted that per-instance state is useful for IoC/DI scenarios, which in turn are handy for testing.

like image 145
Marc Gravell Avatar answered Nov 17 '22 08:11

Marc Gravell