GeeCON Prague 2014*
The moose likes Struts and the fly likes Struts Business Logic Classes called from an Action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Business Logic Classes called from an Action" Watch "Struts Business Logic Classes called from an Action" New topic
Author

Struts Business Logic Classes called from an Action

Andrew Leer
Ranch Hand

Joined: Nov 11, 2003
Posts: 44
Hello,

Should methods in a business-logic class called from a Struts Action always be static methods?

I'd like to use the adapter pattern (composition, i.e. bl.setInterface()) on my business-logic classes.

Thank you,

Andrew J. Leer
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Should methods in a business-logic class called from a Struts Action always be static methods?

No. In fact, generally, they shouldn't be static.

One important thing to understand about Struts is that it does not provide a lot of help or guidelines for writing the model or business logic part of your application. You are therefore free to use whatever classes and whatever patterns your heart desires and they will work just fine within the Struts framework.


Merrill
Consultant, Sima Solutions
Andrew Leer
Ranch Hand

Joined: Nov 11, 2003
Posts: 44
The business-logic methods generally shouldn't be static mainly because, if the same business logic is used in more than one action, than both threads can't access it at the same time correct?

Thanks,
Andy
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
No, the fact that Actions are multithreaded is not the reason your business logic methods should not usually be static. Multiple threads can safely execute a static method, provided it's coded as "thread safe".

The main reason for not making frequent use of static methods is that static methods defeat the purpose of object-oriented programming and design. You want to design your business logic with objects that represent real objects in your business domain and you want to define the behavior of those objects in non-static methods. If all you're doing is calling a bunch of static methods from your Action class, you're not writing object-oriented code. You're writing procedural code. You might as well be writing it in COBOL as Java.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
This is one of the jabs at Enterprise JavaBeans. We are told that statefull EJBs are to heavy weight and that they do not scale well. So we switch over to stateless EJBs which feel a lot like static methods.

What technology are you using for your business tier and data layer?

I am also a little curious about your statement "I'd like to use the adapter pattern"...what is the reason?

- Brent
 
GeeCON Prague 2014
 
subject: Struts Business Logic Classes called from an Action