Reusing methods across actions classes
Hey, Bit of a dummy question here but I am wondering what is the best way to reuse methods across different action classes. Is it acceptable to make an instance of an action class within an action class so I can use one of its methods. Or would it be better to simply copy and paste the method into the both classes. Or should I extract all common methods into one class and create an instance of this class as required. Any suggestions? CH
RE: Reusing methods across actions classes
Yes. call your super class myaction or whatever you feel helps. And also please dont copy both mailing lists. Original Message Follows From: Ciaran Hanley [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: 'Struts Users Mailing List' [EMAIL PROTECTED],[EMAIL PROTECTED] Subject: RE: Reusing methods across actions classes Date: Thu, 30 Sep 2004 11:25:25 +0100 My actions already extend Action. Should I write a superclass that extends Action, and then extend this class, is that correct? Thanks. -Original Message- From: Mark Benussi [mailto:[EMAIL PROTECTED] Sent: 30 September 2004 11:19 To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: Reusing methods across actions classes I would say that if you have common functionality such as a method that all objects [Actions] share then place the common method in a super class [Action] that the other classes can extend. Original Message Follows From: Ciaran Hanley [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts User Mailing List [EMAIL PROTECTED] Subject: Reusing methods across actions classes Date: Thu, 30 Sep 2004 11:16:20 +0100 Hey, Bit of a dummy question here but I am wondering what is the best way to reuse methods across different action classes. Is it acceptable to make an instance of an action class within an action class so I can use one of its methods. Or would it be better to simply copy and paste the method into the both classes. Or should I extract all common methods into one class and create an instance of this class as required. Any suggestions? CH - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Reusing methods across actions classes
Probably you can create a Generic Action class which extends Struts Action class and make all your Action classes extend this class. You can then put the reusable methods in this class and it can be used by all your Action classes. -Prasenjit -Original Message- From: Ciaran Hanley [mailto:[EMAIL PROTECTED] Sent: Thursday, September 30, 2004 3:46 PM To: Struts User Mailing List Subject: Reusing methods across actions classes Hey, Bit of a dummy question here but I am wondering what is the best way to reuse methods across different action classes. Is it acceptable to make an instance of an action class within an action class so I can use one of its methods. Or would it be better to simply copy and paste the method into the both classes. Or should I extract all common methods into one class and create an instance of this class as required. Any suggestions? CH Quinnox is an Award Winning IT services organisation, accredited to CMM Level 5. We are successfully delivering Application Development, Integration, Support and Testing services to clients in the Finance, Manufacturing, Retail and Telecom sectors. Particular focus areas include e-Business and ERP (notably SAP) solutions. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Reusing methods across actions classes
Why don't you just create an abstract action and extend it? Danilo Gurovich Manager, Web Development LowerMyBills.com [EMAIL PROTECTED] 2401 Colorado Ave., 2nd Floor Santa Monica, CA 90404 (310) 998-6412 -Original Message- From: Ciaran Hanley [mailto:[EMAIL PROTECTED] Sent: Thursday, September 30, 2004 3:16 AM To: Struts User Mailing List Subject: Reusing methods across actions classes Hey, Bit of a dummy question here but I am wondering what is the best way to reuse methods across different action classes. Is it acceptable to make an instance of an action class within an action class so I can use one of its methods. Or would it be better to simply copy and paste the method into the both classes. Or should I extract all common methods into one class and create an instance of this class as required. Any suggestions? CH - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reusing methods across actions classes
It may also depend on what kind of code you are trying to reuse. If its something that is action-related (populating a form, etc.) then I would agree with Danilo's answer. If on the other hand, the code is related to business logic that is really independent of the struts portion, then I would put this in a common class that can be reused from as many actions as need it. In a lot of my applications I use a facade for my actions to communicate with seperate objects relating to business logic. This also has the nice benefit of keeping your business logic independent of the particular web solution (in this case Struts) you are using. In fact, you can keep your business logic the same if you decide to write a client server app instead! sean Why don't you just create an abstract action and extend it? Danilo Gurovich Manager, Web Development LowerMyBills.com [EMAIL PROTECTED] 2401 Colorado Ave., 2nd Floor Santa Monica, CA 90404 (310) 998-6412 -Original Message- From: Ciaran Hanley [mailto:[EMAIL PROTECTED] Sent: Thursday, September 30, 2004 3:16 AM To: Struts User Mailing List Subject: Reusing methods across actions classes Hey, Bit of a dummy question here but I am wondering what is the best way to reuse methods across different action classes. Is it acceptable to make an instance of an action class within an action class so I can use one of its methods. Or would it be better to simply copy and paste the method into the both classes. Or should I extract all common methods into one class and create an instance of this class as required. Any suggestions? CH - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Reusing methods across actions classes
Writing your own Action class that extends Action and then extending that to make each class is an option. Depending on the nature of your shared code, it might be easier to just make an ActionHelpers class that contains a bunch of methods, maybe a bunch of static methods even, depending on what the code your trying to share actually is. I've done this in the past because I had some common code at the start and finish of each Action that had to execute (and there was a reason this worked while extending some class didn't, but I don't frankly remember the reason now). -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com On Thu, September 30, 2004 1:13 pm, Danilo Gurovich said: Why don't you just create an abstract action and extend it? Danilo Gurovich Manager, Web Development LowerMyBills.com [EMAIL PROTECTED] 2401 Colorado Ave., 2nd Floor Santa Monica, CA 90404 (310) 998-6412 -Original Message- From: Ciaran Hanley [mailto:[EMAIL PROTECTED] Sent: Thursday, September 30, 2004 3:16 AM To: Struts User Mailing List Subject: Reusing methods across actions classes Hey, Bit of a dummy question here but I am wondering what is the best way to reuse methods across different action classes. Is it acceptable to make an instance of an action class within an action class so I can use one of its methods. Or would it be better to simply copy and paste the method into the both classes. Or should I extract all common methods into one class and create an instance of this class as required. Any suggestions? CH - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]