views:

139

answers:

3

I have started design of a Coldfusion application that is entirely web based. Not much use of Flash forms, or AJAX.

The first version is a strict web app. Version 2 will be a Flex front end.

I want to design and build things so that the Flex layer can use existing logic. It's okay if it means I have to do extra work in version 1. I would like to harden the logic code once and not re-factor.

What are things worth considering / designing / implementing now that would greatly aid in being able to design an app in this way?

+6  A: 

One big suggestion, depending on where you're coming from (as it's a rather big question), would be to leverage the ColdFusion component (CFC) as much as possible; the CFC architecture is excellent, versatile and powerful, it integrates quite nicely with Flex (and will do so even better in coming versions of Flex and CF), so to the extent you can design your component tier with that in mind, you'll be glad you did.

It's been a while since I wrote CF code, but on the last big project I did with it, I spent a good deal of time designing a functional tier out of CFCs to be used by the plain ol' Web app, much as it sounds like you're doing -- and then later, when it came time to bolt on an Ajax UI for a subsection of the site (it could've been Flex, but in my case, it happened to be a YUI implementation), I created a facade layer of publicly exposed CFCs whose job it was to wrap and expose a specialized subset of the functionality provided by the first tier. Doing so allowed me to leverage and extend existing code in a way unique to the services that needed it, without having to expose the underlying (first tier) CFCs directly.

I'm sure other folks will have many more (and probably more detailed) suggestions, but that's the one big one I have for you first off -- learn, know and use the CF component. Good luck!

Christian Nunciato
Thanks for the thoughts. I am leaning towards CFCs and thinking there would be a few tiers of them. Ideally I would like to use Coldfusion's built-in support to use the Flash binary protocol.
Jas Panesar
Sounds like you're on the right track, then. Good luck!
Christian Nunciato
As often is my investigation with Coldfusion, I end up with a "That's it?"
Jas Panesar
If you want to use AMF/Remoting, you pretty much have to work with CFC's - for sure!
RaeLehman
+6  A: 

I agree with Christian that the best thing you can do is put everything as far as database logic or any other logic for the application in CFC's, and more specifically, I would suggest using webservices. The main reason for this is that it will allow you to eventually have your cf code, which is all of your database persistence and logic on a different server than where you serve the flex applications from, and would allow code reuse for other applications as well. The nice thing too about writing your cfc's as webservices is that you can use them either as webservices or directly as components in Flex using AMF (remote object). Now of course how much those benefits really apply to you depends on your situation, but its a good plan to follow.

But the main suggestion is to think of your application as having a presentation layer and a logic and persistence layer. If you are making a decision, it goes in the logic layer. If you are showing a screen or doing anything with presentation, it goes in that layer. Keeping those things separate will allow you to more easily switch out your presentation layer to flex later on.

Also, it can be useful to trap any errors thrown and return messages as results (with any results, like in a structure) from all methods. Flex has a nasty habit of telling you something went wrong, but not passing along the error information. This will help you to debug and handle any errors that get thrown much easier.

Ryan Guill
Thanks Ryan. Already doing the n-tier approach.. Sounds like if I extend the CFC's into web services I will be able to indirectly have multiple ways of using the system without doing extra work. That's the kind of stuff I like!
Jas Panesar
Thanks for your input Ryan, it's good to know I'm not missing that much. I'll make sure the layers behave as best for both CF and Flex. This is quite exciting, to imagine all the work the rest of developers have to do! :)
Jas Panesar
If you add a fault handler to your Flex Remote Objects, you can get useful error info from Flex
RaeLehman
@RaeLehman - this is true, and I probably wasn't very clear when I said this. You can get plenty of error information from cf through flex, even down to the stack-trace, but what you can't get easily (or at least automatically) is debug type information. When writing cf you might be used to being able to throw a dump to the screen at any time. Putting that data in a structure that you are returning along with any results that you did get can help you to get that kind of information too.
Ryan Guill
+3  A: 

Check out Matt Woodward's presentation on the topic, it's very informative:

And a few general things to add to the answers everyone else provided:

  • Encapsulate your data interaction in CFCs (typically in Services which delegate to Gateways and DAOs)
  • In most cases, you'll want to create "bean" CFC's to represent your business objects (users, widgets, etc), these are what will transfer to Flex as ActionScript classes. You'll need to add cfproperty tags to them to make them serializable to ActionScript (case- and order- sensitive!), so pay attention to that when you create them to prevent having to deal with it later, and use one of the code generation tools like the Adobe CF Extensions for Eclipse or Illudium PU36 to do it for you.
  • Create a remote facade CFC (or set of CFCs depending on how big the app is) that delegates methods to your Services - this is where you set the access for your methods to "remote" - generally the only place you want to do this (it will feel like you're doing a lot of delegating but it pays off to have all your remote services centralized)
  • As you develop with HTML, treat your remote facade CFCs as your API and make your HTML views as "dumb" as possible. Think of it this way: any logic you write in your CF view will have to be replicated in your Flex view. If you build the project only using your remote API, you'll have a pretty good feel for how Flex will interact with the application.
  • Check out ColdSpring, it offers a lot of great features for managing all the objects you're going to create!

I don't claim to be an architecture expert and I know I've thrown around a lot of jargon here to keep it short, but some Googling around CF blogs should turn up a lot of info about the design patterns I've mentioned. Good luck!

RaeLehman