Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Business Logic Classes called from an Action

 
Andrew Leer
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andrew Leer
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic