Abstract:
The software model, especially the design model, is becoming more and more important in today's software development. Many standards, tools, and development methods have introduced the concept of patterns. This article introduces how to model the software mode in UML, and introduces in detail how to define and apply the mode in combination with the specific tool rational xde, and pointed out some related problems.
Part 2: Mode mechanism in xde
1 Overview
In the previous series of articles, we briefly and theoretically introduced patterns, especially the modeling methods of design patterns in UML. Now it is time to practice. Currently, there are not many tools that support pattern modeling and application development based on patterns. Rational xde is one of the most famous and indeed provides excellent functions.
There are two types of xde Java versions. One is an independent running version based on the eclipse kernel (currently only eclipse1.0 is supported ). The other one is integrated in wasd and runs as a plug-in of wasd (currently only supports wasd 4.0 ). In fact, wasd uses the eclipse kernel, so there is no major difference between the two in terms of functionality (or even appearance. Now rational has been merged by IBM, so there is enough reason to believe that in the future wsad, xde functions will be more perfectly integrated into it.
Xde has two major selling points: Analysis Design, code writing, and forward-reverse engineering, perfect implementation of model-code ing required in iterative development. The other is the topic of this article: the definition and application of patterns. You can not only use the 23 classic gof design patterns pre-defined in xde, but also define your own patterns, apply them in development, or export them for others.
Pattern mechanism is the core technology used in xde to achieve reuse. You can use this mechanism to reuse model elements and other products. It provides the transformation functions of model-to-model and model-to-code. This allows you to use a model involved as a specific design. It also requires you to merge the elements in a pattern into the existing design model.
2 mode description in xde
In xde, the schema description basically follows the parametric collaboration standard defined by UML. However, the UML only defines how to model the mode, but does not involve too much about how to define the mode, application mode, and specific code generation. Therefore, xde has made some reasonable extensions based on UML.
First, let's take a look at the concept of asset. An asset is a collection of software products that are organized together to solve a problem. Asset can be expanded through its defined variability point. When performing asset reuse, developers need to provide specific content for these variables to enrich asset, to reuse the asset.
Rational is now focusing on an asset based development process method as a supplement to RUP. asset is the key. I am not going to discuss asset and asset based development too much here. It has deviated from the topic of this article. In terms of patterns, you can simply regard asset as the definition, description, and implementation of patterns.
In xde, asset indicates a packet with the <asset> constructor type. Packages declared as <asset> can be exported to facilitate reuse by Different developers or even tools, as long as they all comply with the asset specification reusable asset specification.
Mode is an asset, but asset is not necessarily a mode. A model can be encapsulated in an asset without any schema description. Xde can process these two reusable projects. In xde, the mode is represented as a cooperation diagram containing template parameters in a <asset> package. There are many ways to create a <asset> package, but note that, creating a UML package and manually setting its version to <asset> does not register the package as a mode.
In xde, the <asset> package can be exported as a. RAS file. A. RAS file is actually a zip file, but it has its own content structure, which is similar to the. War file in J2EE. It uses the rasset. xml and resource. XML files to provide a description of the compressed document. The rasasset. XSD file is the XML schema of RAS. It defines the content formats and meanings of rasset. xml and resource. xml. Other files are models and document products.
In xde, the mode consists of the following parts:
Asset
At the bottom of a mode is a <asset> Version package. All content involved in the mode is included in this package. It is also a logical unit used to export reusable models that comply with the RAS specification (the actual physical encapsulation unit is a package, it can also be a model ). The mode may not exist in the asset package. However, this method is not recommended because the mode creation goal is to be reused through the RAS specification.
Template collaboration)
In the asset mode, template collaboration is the core of the mode. Almost all content involved in a pattern is defined in it. You can view the attributes of template parameters through pattern explorer.
Template parameters)
A template collaboration contains one or more template parameters, each of which defines a specific mode input. For example, if you want to have a parameter named myclassinput, you can use that name to create a template parameter.
Type Element)
Each template parameter has a type defined by its type attribute. For example, if the template parameter type is class, the template parameter only accepts the class as its parameter value. When defining a function parameter, you must specify the parameter type (such as INT.
Root Context)
A mode also has a basic context. Other elements introduced during mode Creation are organized in this place. These elements are usually directly created, and few or no parameters are required to create them. For example, a Support class will be used in a mode. By default, the basic context is the asset package. You can switch it to another package in pattern explorer.
In fact, in the asset package where the mode is located, there can be any types of elements, such as class diagrams describing the mode structure, sequence diagrams describing the interaction between participants in the mode, and so on, can be placed in the basic context, and copied to the extension point when the mode is extended.
To provide visual development and representation of models, xde adds a new model perspective (Perspective) based on Eclipse ). In fact, all model-related content, not just the mode, is implemented in this perspective. In addition to model explorer shared by all models, pattern explorer and pattern property view are provided to define and describe the pattern. The use of these interfaces is relatively simple. The key is to understand the attributes and set the values. In addition to the above standard Eclipse graphics elements, xde also introduces pattern Wizard to help you complete the application of the pattern.
3. Application of the Mode
The xde mode can be seen as a template-based method: the template parameters are defined, and the elements that are created or consistent with the template parameter types in the existing model are integrated, to complete the scaling of the pattern. No elements defined as template parameters in the mode will be automatically created at the extension point.
When applying a pattern, there are two basic concepts:
1. Expansion location: place the generated class and other elements after the mode is applied. Even if the schema does not generate any element and its basic context does not involve any element, this extension point is still required for the schema application.
2. binding and binding location ). Binding is a process in which a parameter in the mode is assigned a specific parameter value. This parameter value can be a model element specified by the user or an element automatically created by default. After a mode is applied, a binding object is created in the specified binding point. It is used to maintain the binding relationship between the template parameters of this mode and specific parameter values. Usually, the binding function is used to re-apply the mode after the mode is modified, without the need to re-set the parameter values required for the application mode through pattern wizard, you can also directly modify the bound parameter values in the bound object. By default, the binding point and the extension point are in the same position.
With these two basic concepts, we can simply describe the application of the pattern as follows: where the extension point is located, specify specific parameter values for the parameters defined in the mode and instantiate these parameter values into a specific model. In the package where the mode is located, other elements except the template parameters will also be created, including class diagrams and sequence diagrams.
Take the command mode as an example to illustrate the definition and application of a mode.
To apply the mode, we call up the shortcut menu on the model to be applied, Select Apply favorite pattern, and then select (gof) command mode, for example:
Then the pattern wizard appears to help you enter the pattern parameter values:
The pattern wizard's first page provides a detailed description of the mode and the interaction between the main participants to help developers select the appropriate mode. After clicking Next, enter the parameter value:
There are two methods to specify a common parameter value:
Selected element: for example, You need to specify a type-consistent element in the model. Here is a class. This method integrates the content defined in the template parameters in existing elements without any impact on the original elements.
Generated value: for example, you need to provide a string name for a given parameter and generate an element with a new name.
After a binding value is specified for each parameter, specify the extension point and binding point respectively:
In this way, the application of a model is complete. The semantic information described in the command mode and the specific model elements are introduced into the existing model.
In fact, there are many methods to apply the pattern in xde, but pattern wizard is a standard and simplest method, and xde allows you to define a pattern, make detailed customization for every page in the pattern wizard, making the pattern application more convenient and concise. Other methods, such as constructor and object binding, are not described here.
The application process in xde mode is briefly described. From the perspective of the internal working mechanism of xde, the application of the model is divided into the following three steps:
1. Binding: specify a specific parameter value for each template parameter in the mode.
2. calculation/ ing of parameters: computing parameter-related content, such as constraints and scripts. Map and match parameter values based on the number of specified parameter values.
3. Expand: After all the parameters are determined, the mode can be expanded. The passed parameter values are modified or created, copied to the extension point, and the mode is expanded.
The understanding of this process is very important, because we not only need to apply the existing mode, but also need to define and create the mode. Our understanding of this process gives us a clearer understanding of the template parameters and the relationship between their bindings. This is precisely the core of pattern definition.
4. Schema Definition
From the preceding example, we can easily see that in xde, the key of pattern definition lies in the definition of template parameters, including the type and generation method of template parameters.
Before the Development Mode in xde, we should also refine the abstract mode so that it can be implemented in a specific way. For example, the implementation of the pattern varies with different languages. The refinement process is complicated, and there is no certain criterion. We will not discuss it more here. We will focus on developing a mode in xde in detail.
In xde, you can follow the steps below to develop a mode:
4.1 Creation Mode asset
As mentioned above, a mode is included in a <asset> constructor package. Therefore, you must create this package before creating a mode. You can select Add UML> pattern asset in the context menu of model explorer to create this package. As shown in, the following dialog box is displayed:
Note that an asset can be defined in a package and can be defined separately in a model. This will determine whether the basic context of the mode is the package or the entire model.
4.2 define template parameters for participants
The participants of the mode are the owners of various responsibilities in the mode, that is, the places to be defined by the template parameters. Of course, the template parameters can contain other information, not just the participants of the model. Simply put, the template parameters define all aspects of the mode that need to be customized. To create a template parameter, select Add UML> template parameter from the context menu of the newly created mode collaboration in model explorer. After defining the template parameters, you also need to specify a type for them. Select Add UML in the context menu of the created template parameters, and then select the specific type: Class, method, attribute, interface, String, integer, and so on. Most UML elements can be created as template parameters. Of course, for a mode participant, its type is usually class or interface. For template parameters that are set as class types, we may also need to add attributes, methods, and other content to them. You can also specify a code template for the method. These contents will be introduced into the specific model development with the template parameters.
You can also set the parameter generation method. Determine whether the template parameter value needs to select an existing model element, or create a new one, or derive from other template parameters? These different generation methods depend on the value source value of the template parameter. It can be one of the three cases above or a combination between them. This is a more detailed description of value source in the next section. You can set the value of value source in Advanced properties of pattern between E.
4.3 structure chart of Creation Mode
You can include one or more class diagrams in the schema definition to define the collaboration and relationship between participants in the schema. In model explorer, select Add digoal> class from the context menu of the newly created mode collaboration.
In fact, this class chart is not necessary for pattern applications. However, this class chart can well describe the schema structure, so it is also necessary.
4.4 Add other optional mode elements
You can also add other model elements that are not template parameters for the mode in model parameters E. These elements are placed in the basic context of the mode. When the mode is bound and expanded, they are automatically created and placed at the extension point. In pattern explorer, you can view the content in the root context directory of the pattern.
4.5 create code templates for mode participants
The Code Template fills in the specific code implementation for the methods in the participants. Call up the context menu of a method and select code templates> bind. You can create a new code template for this method, or select an existing code template to bind it to the method.
A special description of the code template will be provided in the following section.
In this way, a complete model is developed. Then we can use the xde pattern Wizard to apply the defined mode to the specific model development.
4.6 Configuration Mode
So far, we have completed most of the development of models. However, there are still some configuration problems that need to be solved. In pattern E, we can configure the pattern so that it can work as expected.
The configuration is mainly distributed in two places and is displayed in the tree directory in Pattern Distribution E. The specific setting value can be modified in the pattern p view. Some are in the Advanced properties of the mode, and some are in the Advanced properties of each template parameter in the mode. For example:
You can customize the content (Application Wizard Properties & Application Wizard icons) and schema description (custom dialogs) of each page that appears in the pattern wizard ), value source, constraints, callouts, and so on. Basically, all schema attributes can be defined and modified. For more details, refer to the subsequent advanced topics.
In this way, the design of a pattern is basically completed. We can export the designed pattern into a standard Ras file through the import/export function provided by xde, for other developers.