当 UML 图上的 return 类型是 object 时,这意味着什么?

What does it mean when the return type on a UML Diagram is an object?

class 国际象棋有一个名为 knighMoves(int i, int j): Chess 的方法,Chess 作为 return 类型。方法 header 会是

public static Chess knightMoves(int i, int j)
{
   return
}

return 语句包含什么?

您的模型告诉我们操作 knightMoves() 不是静态的(图中的静态成员应加下划线),它 return 是一个 Chess 对象。

您可能会感到困惑,因为 return 类型也是封闭的 class。但这并没有改变任何东西。 java 方法看起来像:

public Chess knightMoves(int i, int j)
{
   Chess game;
   … // some code that would assign a value to game
       // and or change its state
   return game; 
}

或根据您的设计意图:

public Chess knightMoves(int i, int j)
{
   … // some code that changes the current object
   return this; // return enclosing object
}