Andy Kramek put together a fantastic blog entry earlier today, titled “Creating Classes with a Factory“. This type of design pattern belongs to the Creational family of patterns, and is used mainly to, um, create things!
What I really like about Andy’s entry is his emphasis on metadata to accompany the pattern. He writes: “[metadata] is what makes this implementation so useful in my opinion, and why VFP is such an ideal tool in which to implement this particular pattern”. And of course, he’s absolutely right!
But more importantly, Andy has uncovered a very useful function of metadata that can be applied to many other elements of software development. That is, the ability to use metadata to store code snippets that can be updated or tested by developers while the executable is running. This isn’t only a handy time-saver, but it’s also a great way to compartmentalize code, deliver custom functions to clients, and build robust and scalable solutions. By including code in memo fields, you can customize applications without changing the core engine. And, as Andy pointed out, you can test various implementations while running the executable.
I’ve used this approach for many years; for as long as EXECSCRIPT has been around. I’ve used to it generate SQL statements on the fly, run conversion routines (some clients like data stored using inches, while others prefer millimeters for example), and separate complex and specialized algorithms that have different implementations depending on the client. I rely on it heavily for all my data integration tasks. In fact, logical data maps (which are more than just “logical” in my world) are used solely to drive all data transformations — not a single piece of business logic is included in the application. The alternative to the metadata approach is to embed these things into the source code itself — but in my experience, this just leads to greater maintenance, regression headaches, and clients that need to wait a little longer.
Using metadata allows you to separate functionality from implementation. In the case of Andy’s Factory pattern, this is one of his important bullet points. In Visual FoxPro, we have the luxury of an in-house, native database that is fast and easy to use. Perfect for metadata (even if you’re using some other database for the backend).