Patterns

From RAD Studio
Jump to: navigation, search

Go Up to Modeling Concepts

Patterns provide software developers with powerful reuse facilities. Rather than trying to solve each design problem from the very beginning, you can use the predefined patterns. The hierarchy of patterns is defined in the Pattern Registry. You can manage and logically arrange your patterns using the Pattern Organizer.

Patterns are intended to:

  • Create frequently used elements.
  • Modify existing elements.
  • Implement useful source code constructions.


Pattern Registry

The Pattern Registry stores the set of patterns. To view patterns stored in the Pattern Registry, use the Pattern Registry viewer. In the Pattern Registry viewer, you can filter patterns by category, metaclass, diagram type, language, or status of registration and view pattern properties. The Pattern Registry viewer can be activated from the Pattern Organizer context menus, using the New Shortcut command when you create a new shortcut, or using the Assign Pattern command when you assign a pattern to a shortcut.

Pattern Organizer

The Pattern Organizer enables you to organize patterns logically (using virtual trees, folders, and shortcuts), view and edit the pattern properties. In the Pattern Organizer, you are working with shortcuts to patterns, not with actual patterns. Shortcuts to the same pattern can be included in several folders.

Templates

Modeling supports templates as a way to provide backward compatibility with the legacy projects from previous versions. You can copy folders with your legacy source code templates to the Patterns subfolder of your installation directory, and use these templates to create elements in implementation projects.

Templates are text files with the language-specific filename extensions that use macros to be substituted with real values when the templates are applied. Therefore, templates can be considered as forms ready for "filling in" with real values. A template consists of the template file containing source code, and the properties file, which contains macro descriptions and default values.

Templates are stored in the Patterns\templates subdirectory of your installation using the following structure:

\<language>\<category>\<template name>

where <category> is CLASS, LINK, or MEMBER. Each <template_name> folder contains the following files:

  • %Name%.<ext>
  • <template_name>.properties (optional)

Design patterns

A design pattern is an XML file that contains a sequence of statements or actions, aimed to create modeling elements and links and set their properties. Each statement creates either one model element or one link between model elements.

In addition to creating new modeling elements, you can use design patterns to add members into a container element. The pattern that you are applying to the specified container element should have its Use Existent property set True. You can apply the pattern to the container element you want to modify. For example, if you want to add several methods stored as pattern to an existing class, then you have to apply that pattern to the diagram where that class exists.

The design patterns are stored as XML files in the Patterns subfolder of your installation.

Patterns as First Class Citizens

A pattern as a First Class Citizen (FCC) is a specific type of design pattern that contains information about the pattern name and the role of each participant. When applied to a diagram, FCC patterns create their own entities and display on the diagram with links to the created entities. Such patterns enable further modifications by means of adding new participants.

FCC patterns are represented by GoF patterns.

A pattern is displayed on a diagram as an oval with the pattern name and an expandable list of participants. Each participant is connected with the pattern oval by a link, labeled with the participant's role.

FCC patterns generate source code. The entities created by patterns are stored in the diagram files.

Stub implementation patterns

When you create an inheritance link between a class and another abstract class or interface, the methods and members are not automatically added to the child class. This problem is solved using the Stub implementation pattern. You can also create an implementation link and stub implementation in one step by using the Implementation link and stub pattern.

If the destination of a link is an interface, the Stub implementation pattern creates the class-source implementing that interface and creates in this class stubs for all methods declared in the interface and in all its parent interfaces.

If the destination link is an abstract class, the Stub implementation pattern generates in the class-source code that extends the class-destination elements. It generates stubs for all constructors declared in the class-destination. These constructor stubs call the corresponding constructors in the class-destination.

You can find the Implementation link and stub pattern in the Pattern Wizard. To open the Pattern Wizard, use the Link by Pattern or Node by Pattern button in the Tool Palette or the Create by Pattern context menu command for a class.

The Implementation link and stub pattern creates the following members of interfaces and abstract classes:

  • Methods
  • Functions
  • Subroutines
  • Properties
  • Indexers
  • Events

See Also