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_refactoring #160

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

Tarea_refactoring #160

Adrianlsq2000 opened this issue Aug 18, 2023 · 0 comments

Comments

@Adrianlsq2000
Copy link

Tarea Reactoring

Tiene un Long parameter list en la clase abstractSshShell esto hace que el código no sea fácil de mantener y modificar podrían a ver complicaciones en el mantenimiento del código. También una lista larga de parámetros puede indicar que está tratando de hacer demasiado y esto puede violar el principio de responsabilidad única.

Recfactorizado

  1. Después
@ToString
@EqualsAndHashCode(of = { "addr", "port", "login" })
@Getter
@SuppressWarnings({ "PMD.UnusedPrivateField", "PMD.SingularField" })
abstract class AbstractSshShell implements Shell {

   /**
    * IP address of the server.
    */
   private final transient String addr;

   /**
    * Port to use.
    */
   private final transient int port;

   /**
    * User name.
    */
   private final transient String login;

   // Introduce Parameter Object for the constructor
   @ToString
   @EqualsAndHashCode
   static class SshConfig {
       private final String address;
       private final int port;
       private final String user;

       SshConfig(final String adr, final int prt, final String user) {
           this.address = adr;
           this.port = prt;
           this.user = user;
       }
   }

   /**
    * Constructor.
    * @param config SshConfig containing address, port, and user.
    * @throws UnknownHostException when host is unknown.
    */
   AbstractSshShell(final SshConfig config) throws UnknownHostException {
       this.addr = InetAddress.getByName(config.address).getHostAddress();
       this.port = config.port;
       this.login = config.user;
   }


   @Override
   public int exec(final String command, final InputStream stdin,
       final OutputStream stdout, final OutputStream stderr)
       throws IOException {
       return new Execution(
          command,
          stdin,
          stdout,
          stderr,
          this.session()
       ).exec();
   }

   protected abstract Session session() throws IOException;
}


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