Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
In some commercial software projects, you cannot afford to cast in stone the structure of business objects. For example, different
companies may have different and even mutually exclusive requirements for Product bean properties. Without a proper framework in place, you may end up spending long hours customizing all your data structures,
including classes, database tables, DTDs (document type definitions), and so on, for every new customer. Needless to say,
you may soon find yourself with a pocketful of parallel software versions and a maintenance headache. How do you ensure that
your design is flexible enough to satisfy varying business requirements without a need to do extra coding each time those
requirements change?
In this article, I lay a foundation for a simple framework I successfully employed to build truly adaptive systems. It is based upon dynamic source code generation from a class's metadata maintained in a data dictionary. In the process, you'll get a refresher on JDBC (Java Database Connectivity) and JSPs (JavaServer Pages), and you'll also learn to generate source code with one of today's most fascinating XML-related technologies, XSLT (Extensible Stylesheet Language for Transformations).
Since we won't design this application for a particular customer, we must make sure we know the business well enough to cover
the most complex cases. To achieve that, we hire the best domain experts, run a few CRC (class-responsibility-collaboration)
sessions, chart several use cases, and eventually assemble a clear understanding of a Product concept, among many others.
With that information on hand, we can build a conceptual business domain model that includes our perfect Product bean depicted below:
|
This is roughly what we do in real projects before the actual coding, especially if we adhere to a good software development process.
Now we can implement the construction phase, where we craft the Product bean's Java code. In Java terms, a bean is a reusable component from either the JavaBean or the Enterprise JavaBean (EJB) frameworks. Despite many significant differences
between the two kinds of beans, there are also similarities. For example, they share the notion of a bean property. The bean
property is based on the standard Java naming convention for the pair of accessor methods. Thus, if the bean has a nonindexed
property code, it is assumed that it provides the writer and reader methods setCode() and getCode(), respectively. The reader method for the boolean type property would be isCode(). For an indexed property, the bean is assumed to possess two sets of setCode() and getCode() methods, one of which would be indexed while the other would deal with the whole array. The java.beans.Introspector uses the same rule set applied in reverse to dynamically analyze the bean class and discover the set of exposed bean properties
on the fly.