Why we use static method in Business Logic?

Showing Answers 1 - 4 of 4 Answers

Anirban Dutta

  • Mar 7th, 2006
 

Instance methods need the class to be instantiated and are hence dependent on that particular instance of the class. Instances of an object can vary widely.

In static methods, all references to it point to one copy only, and are hence independent of the instance. So any method which needs to be independent of the class instance should be declared static. Static methods are specially useful in Factory Methods.

  Was this answer useful?  Yes

Kashyap, Harish

  • Mar 9th, 2006
 

Its a good design practice to implement the business logic in static methods.1. static method access is faster, you don't have to create, initialize the instance. 2. you perform some action/manipulaton on the input data and return the result, so why to make it a bulky object, keep it simpler.3. For holding data you have Beans/Data Objects and for holding client information you have session objectThe nature of the business logic implementation should be generic, i.e. it should not depend upon any pre-condition like initializing some variables, etc. For that use Facade or Validators, or context objects.

  Was this answer useful?  Yes

Instance methods need the class to be instantiated and are hence dependent on that particular instance of the class. Instances of an object can vary widely.In static methods, all references to it point to one copy only, and are hence independent of the instance. So any method which needs to be independent of the class instance should be declared static. Static methods are specially useful in Factory Methods.

  Was this answer useful?  Yes

Hashir Ahmed

  • Apr 7th, 2006
 

Static methods are BAD BAD thing, should b always prohibited. They bind u to a concrete class. Remeber the first good practice of OOP, always program to interfaces rather than classes. Use a factory with singelton rather than a static method. However classes in utils package or utility classes can be implemented with static methods, but not the ones which contain Business Logic.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions