UML类图,如何显示类扩展线程?

2022-09-03 09:43:20

我有一个名为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);
    }

我想在UML中制作一个类图,显示两个类之间的关系,因为我不确定如何在UML中绘制它。它会是一个协会吗?谢谢


答案 1

这将是图,它是一个继承关系(IS-A):

enter image description here


答案 2

这种关系的含义是:“cserver 类是 Thread 类,但 Thread 类不是 cserver 类。

inheritance

我建议您用作类名,检查以下Java命名约定:http://en.wikipedia.org/wiki/Naming_convention_(编程)#JavaCServer


推荐