lundi 7 novembre 2016

What design pattern to use in this situation?

I have 40 suppliers that need to make an ftp connection, do something there and close the connection. So, all of those 40 suppliers have their own class and they all have the connection and disconnection of the ftp server, but they all have different processing methods.

So basically I have 40 classes with this method:

ftp.Connect();
//do something - this is different for all the classes
ftp.Close();

So the do something part is different for all, it does different things, it uses different variables, etc.

What I thought I would do is: create a new class that would be instantiated in all the 40 suppliers. This class will have one method that look something like this:

public void Connect(FTPCredentials credentials, Process process)
{
    var ftp = new FtpConnection(credentials.Host, credentials.Username, credentials.Password);
    ftp.Open();
    ftp.Login();

    process(ftp);

    ftp.Close();
}

public delegate void Process(FtpConnection ftp/*, string name*/);

The problem I have here is that all the methods in all 40 suppliers have different input parameters so what would the input parameters of Process be? Also, I think I don't gain much because I still have the FtpConnection ftp parameter here which means that I will have to add the dll that has the class FtpConnection in every project that will use the Connect method.

For example, the process method in the suppliers would look like this:

process(string fileName) //and it would download fileName
process(string folderName) //create folder if it doesnt exist

Is there a design pattern I can use here that would be cleaner and would make things easier?

Aucun commentaire:

Enregistrer un commentaire