By Tim Landgrave
You can build an environment that allows rapid application development (RAD) using only your own internally developed code (and perhaps some of the application blocks from MSDN). But I think you’re cheating yourself and your company if you don't consider some of the third-party code generation available for .NET developers.
Using a code generator (CG), you can generate hundreds or thousands of lines of code from a simple set of definitions or a database design. Without this technology, your developers would spend hours or days creating much of the same code by hand. Many development shops let their junior programmers create this “grunt code” or send it to offshore developers to save money. But CGs give you something that neither of these scenarios can—consistency.
How code generation works
Generating code from templates ensures that all of the code is created with the same naming conventions, documentation, access mechanisms, etc. No two developers (or even one for that matter) can make that guarantee. CGs work in one of two ways—top down or bottom up.
Using a top-down CG, you define the system by its objects and their interactions, and the CG creates the business objects and the underlying database schema. A bottom-up CG takes your database design and creates a set of data classes and business classes by inferring relationships between the data. Either may be appropriate depending on your circumstance.
If you must interact with an existing database from another system that will continue using the data, you may want a bottom-up CG to simply generate the data classes to accelerate your development process. However, I generally prefer to use a top-down CG because it requires the designer to predefine relationships at a business level, and it does a much better job of creating useful business classes from which you can inherit and extend your design.
DeKlarit: A useful tool for top-down CGs
If you’ve never used a top-down CG before, I strongly encourage you to download a trial version of the DeKlarit tool. I’ve been using this tool for a few months now, and it’s nothing short of amazing. After you define the data elements that describe your systems and the relationship between them, DeKlarit generates a complete business framework (including business and data classes) and the underlying database. DeKlarit codes the business framework classes in either C# or VB.NET and generates database schemas for SQL Server or Oracle.
There are three things about DeKlarit that make it a great tool for system designers. First, you must design only the relationships between your data elements; DeKlarit will generate a well-structured, normalized database schema. Second, if you make changes to your business framework, DeKlarit will regenerate the code and reorganize the database to match the schema while preserving the data. It will also generate a database script that you can run against a production database to make the same changes. Finally, DeKlarit creates test harnesses that allow you to exercise your business framework by inserting, updating, and deleting data using either ASP.NET or Windows forms. Although it’s not the only CG on the market, DeKlarit is the best top-down CG that I’ve used for .NET development.
When to use code generators
Many developers insist that they will not use code from a CG in a production environment. Although I understand their concern for putting code in production that they’ve never actually touched, I think the concern is unfounded. Even if the CG code isn’t used in production, CGs are a great tool for developing detailed prototypes for customers. By allowing the CG to generate the prototype business classes, data classes, and database schema, you have a framework upon which to build your presentation classes, which gives you rich functionality quickly. At a minimum, CG technology can help you unearth potential system issues more rapidly by giving you a more complete prototype. If the CG creates code that you're comfortable deploying, it can shave weeks or even months off of your final development and testing time.