How to label design patterns in Class Diagrams (1)

Source: Internet
Author: User

With the widespread use of design patterns, it has become a hot topic for everyone to discuss how to mark design patterns in structural diagrams (mainly UML class diagrams.The design pattern is some Microstructure in software design. It is helpful for developers to better design the software system and understand some legacy systems through a reasonable method.Specifically, the design pattern annotation has the following meanings:
(1) At the system design and implementation stage, if a mode role can be labeled in a simple and easy-to-understand manner, it will help developers to record the solutions they adopt when developing and designing software, facilitate timely modification and improvement of the design scheme, and help them better understand and modify the source code;
(2) In the system maintenance phase, the code reading and maintenance tasks of legacy systems are very arduous due to missing software documents or departure of core developers, A complex system usually contains hundreds of thousands of files. The relationships between these files are complex. It is difficult to understand the relationships between these files in a short period of time and clarify the design ideas and intentions of the designers, if you can mark the design patterns used in the software in the design documentation and source code, it will undoubtedly greatly simplify the understanding of the system.

UML can only describe the components of the system and their relationships in a visualized manner, and cannot reveal the information related to the design patterns. 1. A chart shows the system design structure. Two design modes are used in this structure, which areBridge pattern)AndAdapter Pattern)The abstract chart class chart acts as the abstract action in the bridge mode, the pie chart class piechart and the bar chart class acts as the refined1_action role, the Data Reading interface datareader acts as the implementor, and the database reading class dbreader and Excel reading class excelreader acts as the concreteimplementor. At the same time, because excelreader reuse the existing class excelapi, the adapter mode is used in the design scheme. datareader acts as the target abstract class (target) role in the adapter mode, and excelreader acts as the adapter, the excelapi acts as the adaptee. If there is no corresponding text description or rich experience in designing patterns, it is difficult to accurately and quickly identify the patterns used and each mode role from figure 1. Therefore,For system designers, implementers, and maintenance personnel, it is of great significance to mark the design pattern in the software design scheme..

In recent years, some design pattern tagging methods have emerged, each with its own characteristics, and there are also some problems and deficiencies. Below I will give a brief introduction to these annotation methods:

1. dimension graph style labels

Venn dimo-style pattern Annotation)It is one of the earliest Design Pattern tagging methods. It was proposed by John vlissides, a pioneer in design patterns, as shown in expression 2. In Figure 2, different design modes are distinguished by solid wireframes and different shadow colors. This annotation method is easy to understand, but there are many problems, for example, when a class plays a corresponding role in multiple design modes, the solid box is overlapped multiple times, affecting the readability of the structure chart; in addition, the use of different shadow colors to represent different patterns will also lead to multi-layer overlapping colors and document printing inconvenience; this method also has the disadvantage of being able to only mark which design patterns are used, instead, you cannot label the mode elements, or mark important information such as class mode roles, methods, and attributes.

My opinion: This method is simple, but too many modes will be messy!

2.Dotted Line border mode Annotation

Dotted bounding pattern Annotation)The method was proposed by Jing Dong at the University of Texas Dallas, as shown in 3. This method solves the problem of shadow overlapping in the dimension graph style labeling method by means of dotted boxes. However, problems such as too simple annotation information and too many line segments in the pattern overlapping area still cannot be solved.

My opinion: This method is also relatively simple, but too many modes will be messy!

3. UML collaborative tagging

UML collaboration notation)The method was first proposed by Grady booch, founder of UML. It was initially used to describe some elements in a general UML image. John vlissides introduced it into the design pattern annotation. In this annotation method, place the name of the design pattern in the dotted line elliptical character, point to a specific model element through the dotted line, and specify the pattern role name corresponding to the model element on the dotted line, as shown in figure 4. However, in this annotation method, the use of a large number of dotted lines will make the entire structure very messy. At the same time, because the mode information and the class structure information are mixed together, these two types of information are hard to understand and recognize. In addition, although this method can mark the pattern role information played by each class, it cannot mark pattern information such as attributes and methods.

My opinion: the mode is not long and clear, but it will be messy and there will be too many lines!

4. "Mode: role" Annotation

"Mode: role" annotation (pattern: Role annotations)The method is proposed by Eric gamma, a pioneer in the design mode. This method uses a shadow box to mark the mode name and mode role name. To save space, if an element only acts as a role in one mode, you can omit the mode name and use the mode role name to mark the role, as shown in Figure 5. This mode annotation method is intuitive and easy to understand, but in a complex structure, the "mode: role" annotation method will make the structure very complex, A shadow box needs to be added for each Schema-related class. As a result, the structure is filled with too many graphic elements. N classes may need 2n shadow boxes, in addition, the position of the shadow box is also very important, and the improper position will cause the structure to be very crowded. In addition, this method does not take into account the annotation of method and attribute details. At the same time, if a class plays a role in multiple instances in the same mode, this method cannot clearly identify different roles in instances in different modes.

My opinion: there are too many elements and layout is too troublesome. If the class diagram is too complicated, this method is not suitable. In Joshua kerievsky's refactoring and pattern book, many images are marked in this way (note: the images are not very complex )!

Summary: I used Visio to draw the above annotation Diagrams (the initial class diagrams are drawn using powerdesigner). It takes a lot of time. If the structure diagram is complicated, I personally think these annotation methods are not very good! The next article will introduce some better tagging methods, so stay tuned!

[Author: Liu Wei]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.