Java UML 类图,如何显示一个类扩展线程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23169691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UML Class diagram, how to show a Class extends thread?
提问by CurryMaster
I have a class called ServerSide in which another class resides called Cserver. The following code fragment should explain what I am talking about:
我有一个名为 ServerSide 的类,其中另一个名为 Cserver 的类驻留在其中。下面的代码片段应该可以解释我在说什么:
public static void main (String [] args) throws Exception
{
System.out.println("The server is running.");
int clientnumber = 1;
ServerSocket server = new ServerSocket(9090);
try
{
while (true)
{
new cserver(server.accept(), clientnumber++).start();
}
}finally
{
server.close();
}
}
private static class cserver extends Thread
{
private Socket socket;
private int clientnumber;
private ConnectionHandler c_handler;
private Protocol protocol;
public cserver(Socket socket, int clientnumber)
{
this.socket = socket;
this.clientnumber = clientnumber;
log("New connection with Client: " + clientnumber + " at " + socket);
}
I want to make a class diagram in UML which shows the relationship between the two classes, as I am unsure as how this can be drawn in UML. Will it be an association? Thanks
我想在 UML 中制作一个类图来显示两个类之间的关系,因为我不确定如何在 UML 中绘制它。会是协会吗?谢谢
回答by aljipa
This is inheritance: http://www.teach-ict.com/as_as_computing/ocr/H447/F453/3_3_6/uml/miniweb/pg6.htm
这是继承:http: //www.teach-ict.com/as_as_computing/ocr/H447/F453/3_3_6/uml/miniweb/pg6.htm
In Java extendsexplicitly defines the IS-Arelationship.
在 Java extends 中明确定义了IS-A关系。
回答by Angular University
This would be the diagram, it's an inheritance relation (IS-A):
这将是图表,它是一个继承关系(IS-A):
回答by carlosvin
The meaning of this relationship is: "cserver class is a Thread class, but Thread class is not a cserver class."
这种关系的含义是:“cserver 类是 Thread 类,但 Thread 类不是 cserver 类。”
I recommend you to use CServer
as class name, check these Java naming conventions: http://en.wikipedia.org/wiki/Naming_convention_(programming)#Java
我建议你使用CServer
类名,检查这些 Java 命名约定:http: //en.wikipedia.org/wiki/Naming_convention_(programming)#Java