UML Designer User's Guide

Message idioms

As with the responsibilities of things, protocol message specifications are characterized by idioms; however, message idioms are distinct from responsibility idioms. When you transform a protocol into a class, message idioms control the stub method implementations generated for the protocol's messages.

Although message idioms are different from responsibility idioms, there are correspondences between them. When you generate a protocol from a thing, UML Designer automatically assigns an idiom to each generated message specification, using the responsibility's idiom to determine which idiom to assign to the messages. (You can also manually select the idiom for a message specification.)

Idiom of responsibility Idioms of generated messages
Action General Message
Identifier
  • Getter
  • Setter

Reference

If max cardinality=1:

  • Getter
  • Setter

If max cardinality=Many:

  • Getter
  • Add
  • Remove

Value

If max cardinality=1:

  • Getter
  • Setter

If max cardinality=Many:

  • Getter
  • Add
  • Remove

For each message idiom, UML Designer generates a different stub implementation when transforming to a class. This section gives examples of both the Smalltalk and Java code generated for each message idiom.

General Message

The General Message idiom is the most straightforward message idiom. It does not make any assumptions about implementation, so it is appropriate for any message. The method generated for a General Message idiom is effectively empty, allowing you to add whatever logic you need. However, the generated method includes comments that identify the parameter and return types for the method as guidelines during implementation.

The following code shows the structure of the Smalltalk method generated from a General Message protocol message with one parameter.

doSomething: p1
 
        "Do something for the receiver
 
        PARAMETERS
                p1 : <Object>
        RETURNS
                <Object>"
 
 
 
        "Put user defined code here."

Following is the Java code generated from a General Message protocol message with one parameter.

	/**
	 * Do something for the receiver
	 * 
	 * @param aString 
	 * 
	 */
	public void doSomething (String aString) {
		
		/* Put user defined code here. */
		
		
	}

Add

The Add idiom describes a message that adds an item to a collection. This idiom is automatically assigned to the "add" messages generated for a responsibility with maximum cardinality of many. An Add message must have one parameter representing the object to be added. A protocol containing an Add message must also contain an attribute for the collection (this attribute is transformed into an instance variable).

The following code shows the structure of the Smalltalk method generated from an Add protocol message.

addMessage: p1
        "Add the argument, p1, to the receiver's collection of aVariable.
 
        PARAMETERS
                p1 : <Object>
        RETURNS
                <Object>"
 
        self aVariable add: p1.
 
        ^p1.

Following is the Java code generated from an Add protocol message.

	/**
	 * Add the argument, p1, to the receiver's collection of aVariable.
	 * 
	 * @param p1 
	 * 
	 */
	public void addMessage (Object p1) {
		this.aVariable.addElement(p1);
		
	}

Getter

The Getter idiom describes a message that returns the value of an attribute. A Getter message cannot take any parameters, and the protocol must contain an attribute to contain the attribute whose value is returned (this attribute is transformed into an instance variable).

The following code shows the structure of the Smalltalk method generated from a Getter protocol message.

getterMessage
        "Answer the receiver's aVariable.
 
        PARAMETERS
                -none-
        RETURNS
                <Object>"
 
        ^aVariable.

Following is the Java code generated from a Getter protocol message.

	/**
	 * Answer the receiver's aVariable.
	 * 
	 */
	public void getGetterMessage () {
		return this.aVariable;
		
	}
 

Remove

The Remove idiom describes a message that removes an item from a collection. This idiom is automatically assigned to the "remove" messages generated for a responsibility with maximum cardinality of many. A Remove message must have one parameter representing the object to be removed. A protocol containing a Remove message must also contain an attribute for the collection (this attribute is transformed into an instance variable).

The following code shows the structure of the Smalltalk method generated from a Remove protocol message.

removeMessage: p1
        "Remove the argument, p1, from the receiver's collection of aVariable.
 
        PARAMETERS
                p1 : <Object>
        RETURNS
                <Object>"
 
        self aVariable remove: p1.
 
        ^p1.

Following is the Java code generated from a Remove protocol message.

	/**
	 * Remove the argument, p1, from the receiver's collection of aVariable.
	 * 
	 * @param p1 
	 * 
	 */
	public void removeMessage (Object p1) {
		this.aVariable.removeElement(p1);
		
	}

Setter

The Setter idiom describes a message that sets the value of an attribute. A Setter message requires one parameter, and the protocol must contain an attribute to contain the attribute whose value is being set (this attribute is transformed into an instance variable).

The following code shows the structure of the Smalltalk method generated from a Setter protocol message.

setterMessage: p1
        "Set the receiver's aVariable to the argument p1.
 
        PARAMETERS
                p1 : <Object>
        RETURNS
                <Object>"
 
        aVariable := p1.
 
        ^p1.

Following is the Java code generated from a Setter protocol message.

	/**
	 * Set the receiver's aVariable to the argument p1.
	 * 
	 * @param p1 
	 * 
	 */
	public void setSetterMessage (Object p1) {
		this.aVariable = p1;
		
	}


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]