You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by tsongwei <ts...@gmail.com> on 2009/07/16 21:59:46 UTC

Design Practice question. Should I use same Action class for different functions?

Hi,

This is a general design practice question.
Say if I am designing User Account Management component that does the
following:
1) User Profile info update -- updates firs name, last name, etc,...
2) Change password. -- do password verification, and change password
3) User Payment info update. -- add credit card info.

My question is, since these three function requires similar info from user,
how many action class should I use?
Should I use one: "UserAccountAction.java"?
or three actions: "UserProfileAction.java", "UserPasswordAction.java", and
"UserPaymentInfoAction.java"?


The approach I took is using one actions: "UserAccountAction".
But the problem is I created many properties and getters setters that are
not used for all struts action mappings.
So I am wondering if this is good practice or not, or should I break it into
three action classes.


How would you design this?

Any suggestion is welcome.
Thanks a lot!!

ST

-- 
View this message in context: http://www.nabble.com/Design-Practice-question.-Should-I-use-same-Action-class-for-different-functions--tp24523385p24523385.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Design Practice question. Should I use same Action class for different functions?

Posted by tsongwei <ts...@gmail.com>.
Hi Dave,

Thanks for your reply. It makes perfect sense.

I should revisit my action classes and do some refactoring....

Thanks,


ST


newton.dave wrote:
> 
> 
> Personally I tend to use multiple actions, mostly to avoid having 
> unnecessary action properties. For me it's easier to deal with many 
> tightly-focused classes (as opposed to a small number of classes with 
> multiple responsibilities).
> 
> I don't think there's a right or wrong way, really--I just happen to 
> prefer keeping classes as light and lean as possible; they're easier for 
> me to read and understand that way. The negative is that I end up with a 
> lot of classes--but I'm okay with that.
> 
> Common functionality often gets broken out into super-classes. For 
> example a recent project now has a user admin action base class with a 
> bunch of services used across all user admin functionality, with a 
> number of sub-classes that handle specific tasks.
> 
> Bigger codespace, more lines of code. Lower cognitive overhead for each 
> class (although it's not always immediately obvious where shared 
> functionality is handled), more granularity making things easier to mock 
> and/or stub.
> 
> Ah, I miss Smalltalk.
> 
> Dave
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Design-Practice-question.-Should-I-use-same-Action-class-for-different-functions--tp24523385p24588625.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Design Practice question. Should I use same Action class for different functions?

Posted by Dave Newton <ne...@yahoo.com>.
tsongwei wrote:
> This is a general design practice question.
> Say if I am designing User Account Management component that does the
> following:
> 1) User Profile info update -- updates firs name, last name, etc,...
> 2) Change password. -- do password verification, and change password
> 3) User Payment info update. -- add credit card info.
> 
> My question is, since these three function requires similar info from user,
> how many action class should I use?
> Should I use one: "UserAccountAction.java"?
> or three actions: "UserProfileAction.java", "UserPasswordAction.java", and
> "UserPaymentInfoAction.java"?
> 
> 
> The approach I took is using one actions: "UserAccountAction".
> But the problem is I created many properties and getters setters that are
> not used for all struts action mappings.
> So I am wondering if this is good practice or not, or should I break it into
> three action classes.
> 
> 
> How would you design this?

Personally I tend to use multiple actions, mostly to avoid having 
unnecessary action properties. For me it's easier to deal with many 
tightly-focused classes (as opposed to a small number of classes with 
multiple responsibilities).

I don't think there's a right or wrong way, really--I just happen to 
prefer keeping classes as light and lean as possible; they're easier for 
me to read and understand that way. The negative is that I end up with a 
lot of classes--but I'm okay with that.

Common functionality often gets broken out into super-classes. For 
example a recent project now has a user admin action base class with a 
bunch of services used across all user admin functionality, with a 
number of sub-classes that handle specific tasks.

Bigger codespace, more lines of code. Lower cognitive overhead for each 
class (although it's not always immediately obvious where shared 
functionality is handled), more granularity making things easier to mock 
and/or stub.

Ah, I miss Smalltalk.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org