Defining, Configuring and Applying Design Patterns

Written Date: December 23, 2008
User Rating: / 2 Hits: 1,307
Add your comment

In VP Suite 3.4 Service Pack 1, there are lots of enhancements in our design pattern support, which gives you higher flexibility in defining patterns. For example, you can define cloneable classes as well as implementation hierarchies. With the enhancements, you can define and apply Gang of Four design patterns to designs effectively.

Defining a Design Pattern

1. Create a project for managing the design patterns. Select File > New Project from the main menu.
2. Give it a meaningful name, such as Design Pattern Repository.
3. Create a diagram for designing the pattern. In this example, we will create a "Builder" diagram for designing the Builder design pattern.
4. Model the Builder design pattern.
5. We know that the design here is just a blue-print. Users of design patterns need to customize the pattern to fit the actual use. In order to let them to configure the pattern, we can assign certain stereotypes to the classes and association to represent the possibility of configuration.
Take the Builder class as example, we want to let users to add more operations to it when applying the Builder pattern. In order to achieve this, assign stereotype "PTN Members Creatable" to the Builder class.
Right-click on the Builder class and select Stereotypes > Stereotypes... from the main menu.
6. Select PTN Members Creatable from the list of stereotypes and press the right arrow to assign it.
7. Press OK to confirm.
8. Assign other necessary stereotypes to associations and classes.
This is a list of pattern-related stereotypes that we can use to make the pattern configurable.
Class
<<PTN Cloneable>> Allow to configure the number of copies of the class.
<<PTN Members Creatable>> Allow to create attributes and operations for the selected class.
Association
<<PTN Operation Impl>> Expected to use for association connecting to the super classes of two hierarchies. This kind of association will cause the target class to implement the operations defined in the source class hierarchy.
<<PTN To-End Role Name Follow Class>> Make the role name of the target end of an association follows the class's name.
9. Having completed the design, we need to save it by defining a pattern. Select all classes being involved in the pattern, right click on them and select Define Design Pattern... from the popup menu.
10. The Define Design Pattern dialog box appear. Give a meaningful name to the pattern, and select a place to store it.
If you save a pattern in workspace, you can take advantage of our team collaboration features to synchronize it to server, so as to share it with other team members.

Applying a Design Pattern

Here is part of a complete design of a class diagram.
Let's create other classes by applying the Builder design pattern we created in the previous section.
1. Right click on the diagram background and select Apply Design Pattern... from the main menu.
This displays the Pattern Selection dialog box.
2. Select the pattern from the pattern list.
The reason why Builder pattern exists in this case is due to it was defined and saved in the same workspace. If we want to add a pattern saved externally, press the Add button and select the pattern file to apply with.
3. Now, let's start to configure the pattern to suit our need. Let's start from the Director class. Select it in the preview.
4. We don't want a class with name Director here. Let's change it to DocumentGenerator.
Besides entering a new name, it is also possible to map it with an existing class on the diagram.
5. Let's proceed with configuring the Builder class.
6. Again, rename it to suit our need. Rename Builder to DocumentBuilder, and rename the operation buildPart to buildHeader.
7. We need to create more operations to the DocumentBuilder for building the main content and footer. As Builder is extending the PTN Members Creatable stereotype, we can add new operations to it by pressing the "+" sign next to the class selection and select New Operation... from the popup menu.
8. From the Operation Specification it popped up, enter the operation name as well as other information needed, such as parameters.
9. For this case, we also need to set the operation as an abstract one. By doing so, concrete subclasses will inherit this operation.
This complete configuring the Builder class.
10. Let's proceed with configuring the ConcreteBuilder class.
11. We want to create several document builders for generating documents in different formats. As ConcreteBuilder is extending the PTN Cloneable stereotype, we can clone it to create more copies by pressing the "+" sign next to the class selection and select Clone... from the popup menu.
12. Enter the number of classes to clone.
13. This end up having 3 concrete builder classes. Rename them.
14. Configuration done. Press OK to apply the pattern to the diagram. This is the outcome:
15. Rearrange the classes and add necessary connectors. Here is the completed diagram.

Resources

• Visual Paradigm for UML Home
http://www.visual-paradigm.com/product/vpuml/
• Agilian Home
http://www.visual-paradigm.com/product/ag/
• SDE Home
http://www.visual-paradigm.com/product/sde/
• Download Visual Paradigm for UML
http://www.visual-paradigm.com/product/vpuml/vpumldownload.jsp
• Download Agilian
http://www.visual-paradigm.com/product/ag/agdownload.jsp
Software Maintenance VP-UML User's Guide

Rate this Article

Click on one of the stars below to rate this article from 1 (lowest) to 5 (highest).

Comments (0)

Write comment

Rating

Comment

Enter the calculation result

security code