-1

So to give some context I'm making a project for an architecture class, and I'm trying to debug some problems with my WebService, for this I created a library class that mimics the functioning and logic of the WebService. But I find that I need to change a lot of code every time I find some bug and I was thinking that there could be a better and smarter way to resolve this that I simply don't know yet.

This is the way I handle most of my functions and methods:

private void btnLogin_Click_1(object sender, EventArgs e)
{
    IntegracionLogin auxLogin = new IntegracionLogin();
    //NegocioLogin auxLogin = new NegocioLogin();
    Login aLogin = new Login();
    String nombre = this.txtNombreUsuario.Text;
    String contrasena = this.txtContrasena.Text;
    try
    {
        String respuesta = auxLogin.IValidaLogIn(nombre, contrasena);
        //String respuesta = auxLogin.ValidaLogIn(nombre, contrasena);
        Console.WriteLine("dfasf" + respuesta);
        if (respuesta.Equals("Cliente"))
        {
            MessageBox.Show("Estimado Cliente, Bienvenido");
            MenuCliente pantCliente = new MenuCliente();
            pantCliente.ShowDialog();
        }
        else if (respuesta.Equals("Empleado"))
        {
            MessageBox.Show("Estimado Empleado, produce plata");
            MenuEmpleado pantEmpleado = new MenuEmpleado();
            pantEmpleado.ShowDialog();
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("error de logIn :  " + ex + "\n");
        MessageBox.Show("UwU!" + "\n" + "No se encuentra en el sistema," + "\n"
                            + "si cree que fue un error contacte con el administrador.");
    }
    aLogin.Dispose();
}

About the code I just showed you, this is the line I'm concerned about:

IntegracionLogin auxLogin = new IntegracionLogin();

This method is sort of simple as it doesn't need to instance a lot of other classes, but when I try to debug or integrate the WebService layer, I need to change hundreds of lines every time... So I thought this is really inefficient and maybe there could be a better way to handle this.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • I meant to ask if there is a way to maybe instantiate in a method all of these lines (refer to second code block) so that I only need to modify that method instead of 200 to 1000 lines that are mostly equals... I thought programming was about trying to minimize redundancy. If you could can you offer me insight as if the question is not clear to what I intend to convey? or if I misunderstood the general idea? @TaW (I feel like you are mocking me, but maybe I'm misunderstanding) – Christian Villarroel Jul 05 '20 at 10:08
  • IDK why I lose my time using this site, I'm not in the mental state where I can take much criticism in a good light, anyhow I was just asking something trying to be as polite and clear as possible. But thankfully someone directed me into the into something called "Factoring" witch is what I needed. – Christian Villarroel Jul 05 '20 at 11:03
  • Whereever you go, always make sure to read the rules of the site! Your post break pretty much all rules and recommendations. Do read the help pages! Good luck! Hint: SO is not just there to help you but to collect useful questions and answers into a large archive. Re-read you post and ask yoursel how much of it will be useful for furtue readers!! All the rest (aka 'fluff' ) should not be there. – TaW Jul 05 '20 at 11:16
  • 1
    @TaW so... yeah you were right, I was using the site wrongly. Thanks for correcting me. – Christian Villarroel Jul 07 '20 at 01:26

1 Answers1

0

so if you are having this problem I suggest you to look into using a "Factoring" approach, it can be better explained by looking at this post

It should help to reduce the amount of lines needed to modify when trying to debug and changing the layers used in an n-layered approach.

E_net4
  • 27,810
  • 13
  • 101
  • 139