Working with patterns

Together delivers a unique capability to extend its functionality externally by using modules and patterns. Modules are discussed in User's Guide: Working with Modules. This topic explains how to use the "pre-fab" patterns included with Together, and discusses the basic structure of patterns and points you to information on how to deploy your own patterns.

About patterns

Together patterns are public Java classes implementing an interface called com.togethersoft.openapi.sci.pattern.SciPattern.

Patterns are used to create frequently used elements, to modify existing elements, or to implement useful source code constructions or solutions in your model. For example, Together ships with a set of GoF patterns including Visitor, Observer, Singleton etc.

Some patterns work only with a specific language. Enterprise Java Bean patterns, for example, can work only with the Java language. GoF patterns are currently available as Universal. Other patterns can be applied to any language- the pattern.UNIVERSAL.MEMBER.Stub_implementation pattern for example. Together determines the target language for a pattern automatically, and identifies its location in the installation. See details below.

Behavior of a pattern is defined by its properties set. The getProperties method returns a com.togethersoft.util.propertyMap.PropertyMap instance containing a set of all the properties for the pattern.

The SciPattern interface defines the methods that you should implement in your pattern:

Other information about pattern-related interfaces and pattern properties can be found in the main API documentation (/doc/api folder in your Together installation).

Creating classes and links from patterns

Together makes it easy for you to apply patterns when creating classes or links. When creating classes or links during modeling, you can use the following on the Class Diagram Toolbar:

Tool-tip

Icon

Description

Class by Pattern

 

Create a new class using a selected pattern to define how code is generated

Link by Pattern

 

Create a relationship link using a selected pattern to define how code is generated

Both icons launch the Choose Pattern dialog displaying the available patterns for the respective operation. You can access Together's predefined patterns plus any that you implement yourself. The dialog has an "expert" format.

To create a class or link from a pattern:

  1. Click the appropriate toolbar icon.

  2. If creating a class, click on the Diagram pane to display the Choose pattern dialog for classes. If creating a link, drag it from the source class to the destination and drop it to display the Choose pattern dialog for links.

  3. Select the pattern you want for the new class or link.

  4. If the Next button is enabled, there are properties or parameters for the pattern. Click Next to display them. (If you know the pattern and want to accept the defaults, click Finish).

  5. Set properties or parameters as desired and click Finish.

NOTE: Users of the Microsoft JVM should note that java.rmi classes, required for compilation of the EJB pattern, are not present in this JVM.

Creating members by pattern

There is no toolbar button for this operation. Invoke class speedmenu and select New | Member by Pattern. Choose Pattern dialog shows up, where you can select the desired property pattern. Enter property name and type, and check the boxes for accessor methods and attributes if necessary.

Choosing a pattern for a Member

You can also apply patterns to control the way implementation code is generated for an attribute or operation.

To apply a pattern to a member:

  1. Select an attribute or operation and select Choose Pattern from its speedmenu. The Choose Pattern dialog is opened displaying available patterns for members

  2. Select the pattern you want for the member. The resulting code displays in the Preview box.

  3. If the Next button is enabled, there are properties or parameters for the pattern. Click Next to display them. (If you know the pattern and want to accept the defaults, click Finish).

  4. Set properties or parameters as desired and click Finish.

The dialog's "Member" node displays patterns that can make the selected member an attribute, an operation, or even regenerate the code for the property with get and set method. The "Link" node displays patterns that make the selected member a link.

Note: The "Choose Pattern" menu command is enabled only if the selected element satisfies certain criteria that make possible regeneration without losing significant code. Thus, if an operation already has some code in its body, the command is disabled.

Refactoring with patterns

You can also refactor existing classes or links replacing an existing pattern with a better one. You can do this singly, or to multiple selected elements.

To refactor classes or links:

  1. Select the element(s) in the Diagram pane. (E.g. select multiple classes).

  2. Right-click on the selected element (or one in a group) and choose Choose Pattern from the speedmenu to display the appropriate Choose Pattern dialog.

  3. As above, select the desired pattern for refactoring, set any properties or parameters, and click Finish.

Tip: You can also access the Choose Pattern dialog from the speedmenus of Class diagram elements in the Explorer.

Developing and deploying your own patterns

You can develop your own patterns and reuse them in Together. Patterns are implemented using the SCI API. To develop your own patterns you will need to study the documentation for the Together API. (For more information on the API documentation see Reference: Together Open API.) You can also study examples of mature patterns in the $TOGETHER_HOME$/modules/com/togethersoft/modules/patterns directory in your installation. To deploy your patterns, you must place them in the proper package under this directory. For more information and technical specifications for deployment, see the file $TOGETHER_HOME$/modules/com/togethersoft/modules/patterns/patternsReadMe.html.