By Peter Bell

Application Generation: Orchestrating the Process

If you store metadata about your applications in the same way that you store data about pages or users or products, then an Application is just another business object making it easy to list, add, edit and delete entire applications in the same way as you list, add, edit and delete articles or product categories (see why I like putting my metadata into a database?!).

Of course, you need a “generate” method so you can ApplicationService.generate(MyApplication,”application”), passing an application IBO into the generator. But I really don’t think that applications should know how to generate themselves, so we need to compose the ApplicationService with a Generator.cfc which I’m going to put into a subdirectory in my library (.com.lib.generate) so when I add other generation focused cfc’s I have the option of putting them in the same directory and using the package (Java: protected) scope, treating generator.cfc as a facade to the entire generation process.

Initially I’m just going to give Generator a single public generate(Object,ObjectName) method which orchestrates the generation process for a given application as I want to keep it as shy as possible. I can always open up the interface a little later if I need to.

The generate() method is a strategy pattern using the ObjectName to call generate#ObjectName#() if it exists. Usually this would seem like unreasonable indirection, but I am not sure of the relationship between generators and methods (maybe one method will generate all object types – maybe only some object types will be generatable – maybe groups of types of objects will share a single generate method) so I’m going to encapsulate that potential variability upfront and then see where things go from there.

So, how should the application generator work? I’m looking to just orchestrate a bunch of discrete calls for provisioning directories, static files, CF templates, DSNs and IIS sites and for generating methods, classes and other scripts. I’m going to start by putting together a lot of little cohesive components for handling each of these issues (hey they’re singletons – how much does it really cost?!) and once I’ve got the interfaces down and each component working in a test harness, I’m going to have to write just a little bit of ORM goodness (a getAssociated() base IBO method) to get all of the directories and fields and methods and classes that relate to a given application to efficiently generate everything with a single lazy initialized “Application” object.

Comments
Peter,

Why don't you think an application should know how to generate itself? I am interested to hear drawbacks of that approach because it is my MO.
# Posted By Steve Bryant | 10/9/06 7:21 PM
Well, it is more a matter of whether I feel it is cohesive or not to have the actual generation methods within the ApplicationService. I felt it would be extremely convenient and useful to have an ApplicationService.generate(MyApplication) method but felt it would be best to use composition, getting that method to call a Generator.generate(MyApplication,"application") method, so it wasn't a broad disagreement with inline generation (which I actually quite like even though I don't use it all the time) but a subtle distinction about whether to use composition or to include the actual code for the generation methods within the ApplicationService which I felt was not cohesive.

However, cohesion is often a matter of preference, previous experience and currently popular approaches in your language(s) of choice, so I wouldn't disagree with putting the generation code within ApplicationService, it just wouldn't be my personal preference.
# Posted By Peter Bell | 10/9/06 8:13 PM
The more general debate over inline generation comes down to whether you'd like to have a more minimalist application which runs but doesn't know how to generate itself and to have an external dependency on a generator or whether you'd rather include the ability for an application to generate itself within the application which in some ways seems a little strange, but has the benefit of removing the external dependency.

Sometimes there are business reasons for the choice. If you are working for hire but using your own properietary generator, you may use an external generator so clients have to pay every time they want you to regenrate functionality. If you don't generate too many applications, I would definitely recommend including yur generator as part of your code otherwise you'll end up with generators and applications that are out of synch and it becomes a mess. If you are committed to a true software product line approach, there is nothing wrong with having an external generator (and regenerating all of your apps automatically every time you upgrade it), but there is also a place for inline generation.

I don't think there is a "right" answer and I think as people move towards generating applications most people will use a combination of the two approaches.
# Posted By Peter Bell | 10/9/06 8:18 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.