Normally, when code is identical among objects of the same type, one would use inheritance to handle this. That is, making a controller extend another controller.
AOP is used to direct preprocessing or post processing of a specific method call. By using AOP you can wrap method calls and run processes either before or after the wrapped method call. Some like to do this if there are processes to add before lots of method calls, like Logging or writing Audit logs. Others feel that AOP is a bit far removed from the processing and is hard to debug especially down the road where the original developer is no longer there. Most people would have a hard time figuring out where the heck something was coming from, since it isn't referenced in the method that performs the original work. That doesn't mean you should avoid it completely, there are good use cases and good ways to document the use of AOP to alleviate the maintenance issues. However, in your case, it looks like these methods are not to be wrapped around another method, but that the implementation of the method is similar to other methods in your controllers. If I'm right to say that, then AOP would not be the right choice to reduce code duplication. Either you should use inheritance ( one object extends another), or you should use composition (stick these methods in another object that is available to your controllers). I'd probably vote for composition as it usually is the right decision and is easy to refactor later. Inheritance can be a pain in the bum, especially when a design decision needs to be changed later. DW On Tue, Jan 18, 2011 at 10:57 AM, marc <[email protected]> wrote: > Hi Dan, > > Below are 3 functions I use in 5 controllers. They do different things > but all have code in common. I only show here the code they have in > common. > > <cffunction name="list" access="public" output="false"> > <cfargument name="event"> > <cfset var localData={}> > <cfset > > arguments.event.setValue("bedrijfIterator",beans.bedrijfService.list(userId=beans.sessionService.getUserId(),bedrijfTypeId=arguments.event.getValue('bedrijfTypeId')))> > <!---create urls---> > <cfset > localData.controller=ListFirst(event.getEventHandlerName(),".")> > <cfset > > arguments.event.setValue("xeView",arguments.event.linkTo("#localData.controller#.view#arguments.event.getValue('bedrijfTypeTitle')#"))> > <cfset > > arguments.event.setValue("xeNew",arguments.event.linkTo("#localData.controller#.new#arguments.event.getValue('bedrijfTypeTitle')#"))> > <cfset > > arguments.event.setValue("xeDelete",arguments.event.linkTo("#localData.controller#.delete#arguments.event.getValue('bedrijfTypeTitle')#"))> > </cffunction> > > <cffunction name="new" access="public" output="false"> > <cfargument name="event"> > <cfset var localData={}> > <cfset > > arguments.event.setValue("bedrijfBean",beans.bedrijfService.new(arguments.event.getValue('bedrijfTypeId')))> > <cfset arguments.event.setValue("disabled",false)> > <cfset arguments.event.setValue("newBedrijf",true)> > <!---create urls---> > <cfset > localData.controller=ListFirst(event.getEventHandlerName(),".")> > <cfset > > arguments.event.setValue("xeSave",arguments.event.linkTo("#localData.controller#.save#arguments.event.getValue('bedrijfTypeTitle')#"))> > </cffunction> > > <cffunction name="save" access="public" output="false"> > <cfargument name="event"> > <cfset > localData.bedrijfTypeId=arguments.event.getValue("bedrijfTypeId")> > <cfset > > beans.bedrijfService.save(bedrijfBean=arguments.event.MakeEventBean(beans.bedrijfBean),bedrijfTypeId=arguments.event.getValue("bedrijfTypeId"))> > </cffunction> > > I thought of factoring this code out in an advisor and apply that > advisor to the 5 controllers. > > Marc > > -- > Model-Glue Sites: > Home Page: http://www.model-glue.com > Documentation: http://docs.model-glue.com > Bug Tracker: http://bugs.model-glue.com > Blog: http://www.model-glue.com/blog > > You received this message because you are subscribed to the Google > Groups "model-glue" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<model-glue%[email protected]> > For more options, visit this group at > http://groups.google.com/group/model-glue?hl=en > -- Plutarch - "The mind is not a vessel to be filled but a fire to be kindled." -- Model-Glue Sites: Home Page: http://www.model-glue.com Documentation: http://docs.model-glue.com Bug Tracker: http://bugs.model-glue.com Blog: http://www.model-glue.com/blog You received this message because you are subscribed to the Google Groups "model-glue" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/model-glue?hl=en
