CMPUT 301

Software Engineering

Practice w23hm3q2


Midterm 3 Question 2 (March 29) -- Hindle

Submit a PDF, PNG or JPEG

5 marks

You must add your CCID to your answer

Template Method Pattern Refactoring (Java Code to UML Class Diagram)

This code represents code that establishes an encrypted connection using TLS 1.2 or TLS 1.3 protocols. TLS 1.3 is faster to establish than TLS 1.2 because it does more work in fewer messages.

Restructure this code with the template method pattern and provide a UML class diagram depicting the structure and operations one would expect after refactoring this code to use a template method. Your solution must significantly reduce code duplication and enhance reuse.

You must provide the template method Java code in a UML comment (see example below).

Image

Draw the resulting UML class diagram of the refactored code. Provide the basic abstractions, attributes, methods, relationships, multiplicities, and navigabilities as appropriate. "...” or “//” means much code is omitted.

interface Socket {
    /* ... /
}
class TLS12 {
    Socket socket = null;
    Socket encryptLink(Socket s) {
        this.socket = s;
        clientHello();
        serverHello();
        csKeyExchange();
        return wrapSock();
    }
    void clientHello() { / ... / }
    void serverHello() { / ... / }
    void csKeyExchange() { / ... / }
    Socket wrapSock() { / ... / }
    / ... /
}
class TLS13 {
    Socket socket = null;
    Socket encryptLink(Socket s) {
        this.socket = s;
        clientHello();
        serverHelloWExchange();
        return wrapSock();
    }
    void clientHello() { / ... / }
    void serverHelloWExchange() { / ... / }
    Socket wrapSock() { / ... */ }
}