【问题标题】:What does it mean when the return type on a UML Diagram is an object?当 UML 图上的返回类型是对象时,这意味着什么?
【发布时间】:2021-11-30 19:44:51
【问题描述】:
Chess 类有一个名为knighMoves(int i, int j): Chess 的方法,返回类型为Chess。方法头会是
public static Chess knightMoves(int i, int j)
{
return
}
return 语句包含什么内容?
【问题讨论】:
标签:
java
class
methods
uml
class-diagram
【解决方案1】:
您的模型告诉我们操作knightMoves() 不是静态的(静态成员应在图中带下划线),它返回一个Chess 对象。
您可能会感到困惑,因为返回类型也是封闭类。但这并没有改变任何东西。 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
}