The software must connect to a server, the server can be of a different type (for example FTP and SQL), after the connection the software must perform some actions, for example download a list of something.
We have different type of server, so if the software is connected on a FTP server, the action is download a list of files, if the software is connected on a SQL server the action is a query on a table.
When the software starts, it loads a configuration file, on this file there are some server informations, what happen in reality is a population of a list of ServerInfo objects, each object contains the server type, the address and the login data.
I'm searching an elegant and transparent solution, I don't want code like this:
Expand|Select|Wrap|Line Numbers
- Server server;
- if (serverInfo.type == FTP)
- server = new FTPServer();
- else if (serverInfo.type == SQL)
- server = new SQLServer();
- server.connect();
Thanks.