Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tarea Refactoring1 #161

Open
Adrianlsq2000 opened this issue Aug 18, 2023 · 0 comments
Open

Tarea Refactoring1 #161

Adrianlsq2000 opened this issue Aug 18, 2023 · 0 comments

Comments

@Adrianlsq2000
Copy link

Tarea Refactoring

Beneficio de hacer la refactorizacion es que se reduce la complejidad del método original en AbstracSshShell y esto hace que el código sea más claro y fácil de entender.

También encapsulamos la lógica en una clase separada entonces cada clase tiene una responsabilidad más específica una única responsabilidad. La clase ExecutionMethodObject puede ser reutilizada en otra parte que se necesite sin duplicar código. Cualquier futura modificación se podría hacer en la clase ExecutionMetodObject sin afectar la estructura general de AbstractSshShell.

Codigo despues de la refactorizacion

  • Clase exec
@Override
public int exec(final String command, final InputStream stdin,
    final OutputStream stdout, final OutputStream stderr)
    throws IOException {
    return new ExecutionMethodObject(this, command, stdin, stdout, stderr).execute();
}
  • Nueva clase ExecutionMethodObject
class ExecutionMethodObject {
    private final AbstractSshShell sshShell;
    private final String command;
    private final InputStream stdin;
    private final OutputStream stdout;
    private final OutputStream stderr;

    ExecutionMethodObject(AbstractSshShell sshShell, String command, InputStream stdin,
        OutputStream stdout, OutputStream stderr) {
        this.sshShell = sshShell;
        this.command = command;
        this.stdin = stdin;
        this.stdout = stdout;
        this.stderr = stderr;
    }

    int execute() throws IOException {
        Execution execution = new Execution(
            command,
            stdin,
            stdout,
            stderr,
            sshShell.session()
        );
        return execution.exec();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants