UML Class diagram, how to show a Class extends thread?

安稳与你 提交于 2019-11-30 02:56:10

问题


I have a class called ServerSide in which another class resides called Cserver. The following code fragment should explain what I am talking about:

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


回答1:


This would be the diagram, it's an inheritance relation (IS-A):




回答2:


The meaning of this relationship is: "cserver class is a Thread class, but Thread class is not a cserver class."

I recommend you to use CServer as class name, check these Java naming conventions: http://en.wikipedia.org/wiki/Naming_convention_(programming)#Java




回答3:


This is inheritance: http://www.teach-ict.com/as_as_computing/ocr/H447/F453/3_3_6/uml/miniweb/pg6.htm

In Java extends explicitly defines the IS-A relationship.



来源:https://stackoverflow.com/questions/23169691/uml-class-diagram-how-to-show-a-class-extends-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!