|
9.5 Patterns In Practice
Patterns in the literature are normally used to advise software architects on how to create architectures, and then to change a design (e.g. the UML model) so that more design features are created. The end result of using a pattern in this way is that the design is permanently changed. This approach has the drawbacks of using a wizard: it is often difficult and time-consuming to reverse the effects of using a design pattern. In JeeWiz, our goal is automation of the development process, so patterns are applied automatically (by the presence of one of the *includeSpec.vm files, as we saw earlier in this chapter). Furthermore, we want to create the eventual software system, not change the original design. There is a very good reason for this: a different rendering of the system will need different architectural patterns. If we apply patterns at design time and change the model, it precludes automatic re-rendering to address new architectures. So in JeeWiz, architectural patterns operate at generate time, not at design time. Because patterns are applied automatically, as determined by the architect, the modeler can guide the way patterns start by various means (by the stereotypes in UML models, or elements tags used in an XML specification and the various properties the modeler can specify to guide the process), but once started, the process is determined by the architectural patterns. Finally, the MDA literature talks about multi-stage processes where the specification (logical model, or PIM) is converted to a PSM (platform specific model) which can then be transformed again and so on. A modeler can change the PSM after each conversion. The final stage is to convert the PSM into the final textual products, like code and descriptors. Each conversion step in this process is called a 'transformation'; it is relevant to this discussion, because a transformation operates like a group of coordinated patterns. In JeeWiz, there is no separately accessible PSM: we go from a PIM to final textual products automatically. The final 'PSM' can be produced, but it is typically only used for debugging. This means that patterns and templates completely govern the conversion from the PSM to the final framework, ready for the application programmer to add the specialised business logic.
These files occasionally implement patterns themselves. For example, as of this writing (which phrase we will now assume and omit!), the preIncludeSpec.vm for the BOM:entity implements the pattern 'ensure an entity has a primary key':
While this is a typical usage of the preIncludeSpec.vm (i.e. slightly massage the definition of an object before other patterns fire), the includeSpec.vm file is normally used as a coordinator for components of the patterns. The includeSpec.vm does this by including other files: by convention these are given a 'inc' extension. For example, the component to create a factory class that manufactures proxies for business objects is called BOMFactory.inc. This is part of the larger-scale patterns, represented by the includeSpec.vm for a business object:
Other types of renderings can of course produce different representations and many output files, depending on what is in the build.xml for the type of object. In the same way that the 'includeSpec.vm' can coordinate multiple pattern components, the build.xml can coordinate many parts of the rendering. This may produce artifacts (e.g. deployment descriptors, second-stage build jobs) or binaries (e.g. jars). Renderings are typically platform-specific: for Java platforms, Java language files are generated and built using Java tools.
However, in real-life the modeler may want to give hints to the build process for a particular object. He does this using the 'style' attribute, which is available on all objects. This can then give hints to the generation process; these hints are interpreted by patterns and templates as the objects are fired. For example, a 'property' modeled in UML could be mapped to an XML element (e.g. <property>value</property> ) or attribute (e.g. property="value"). Styles can be used to guide both patterns and templates.
The current mega patterns are overviews in the following diagram and detailed below:
Copyright (c) 2001-2008 New Technology/enterprise Ltd. | ||||||||||||||||||||||||||||||||||||||