Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best Practices for Business Logic

Status
Not open for further replies.

GryphonsClaw

Programmer
Oct 3, 2005
9
0
0
US
What is the best practice for separating business logic from presentation?

I do a lot of simple programming on our intranet site, mostly form submit to query a database and display a report. I have a CFC that does the query and a cfm that loops through the returned query variable and displays the results. If I am looking to do multiple actions based on the form, would it be best to pass the form variable to the CFC and do the logic there.

An example would be the user selects to filter a report by customer. I have the invoke on the cfm page where I look to see if the customer field is defined, if so I include the Customer argument of the components method. Sometimes I will invoke different methods based on the FORM fields selected. Should I just pass the FORM variable to the method and do this logic there? Am I over thinking this, and it really doesn't matter?
 
I am not 100% sure on the 'best practice' way of doing this, but i prefer to keep ALL business logic in cfc's. This way you can write a new presentation layer for your application without worrying with the logic. This also helps me as i like to expose some web services as an API for my app, having all the business logic contained makes it much more effective.

I would research design patterns (MVC in particular) if i were you.

I would consider this one of the best methods for doing this.


=========================================
I have not failed. I've just found 10,000 ways that won't work.
Thomas A. Edison
 
I would agree 100% with northstar - better to keep all business logic in cfcs, you can also go one step further and create a db layer so db interactions are encapsulated in cfcs - this means changes to the db platform will be invisible to your business logic cfcs. I prefer to use custom tags only for view logic - i.e. rendering content on the final pages. Finally by using cfcs for your business logic although it may seem like more work now you can also use cfcunit to unit test your cfcs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top