Instanceof design doubt in Java
08/01/2019 12:08
HiI have a problem in a program design. I want to implement anapplication that transfer files between two folders. Folders can be inthe same or remote computer and can have differents types (ftp or filecopy, for example). For example, I want to transfer a file from ashared folder in a remote computer to a remote ftp site. I have madethis design:

public class Site { String folder;}public class RemoteSite extends Site { String host; int port;}
public abstract class TransferType { public abstract get (Site site, String file); // transfer file fromsite to local public abstract put (Site site, String file); // transfer file fromlocal to site}public class CopyType extends TransferType { public void get (Site site, String file) { if (site instanceof RemoteSite) // do transfer else // do transfer }
public void put (Site site, String file) { if (site instanceof RemoteSite) // do transfer else // do transfer }}public class FtpType extends TransferType { String user; String password;
public void get (Site site, String file) { ...instanceof ... } public void put (Site site, String file) { ...instanceof ... }}
public class Transfer{ Site origin; Site destination; TransferType typeOrigin; TransferType typeDestination;
public void transferFile (String file) { typeOrigin.get (origin, file); typeDestination.put (destination, file); }}
Does somebody knoes how avoid instanceof in TransferType classes? Ihave thought in others designs but I haven't got a good solution.


ThanksDavid

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
08/01/2019 12:08 - I don't know why you would use instanceof anywhere in a filetransfer program. I didn't.

I wrote a program which copies a directory of files from a unix serverover the internet to a windows server, usingorg.apache.commons.net.ftp.FTPClient.


Source is Usenet: comp.lang.java.help
Sign in to add a comment

eDiscover
Helpforce eDiscover provides technical articles updated each dayHelpforce eDiscover RSS feed contains the latest technical articles in RSS
Click the logo to go back to the main page
Search eDiscover
  
Categories

Click an icon to go to that category

Helpforce eDiscover contains articles about Microsoft Windows Helpforce eDiscover contains articles about Apple products and MacOS Helpforce eDiscover contains articles about Linux and POSIX operating systems Helpforce eDiscover contains articles about Helpforce Helpforce has a large variety of technical information and articles for you to read Helpforce eDiscover contains articles about databases, MYSQL, SQL Server Oracle Helpforce eDiscover contains articles about Java, JVM and the JRE Helpforce eDiscover contains articles about the QNX operating system Helpforce eDiscover contains articles about Oracle Solaris and Open Solaris Helpforce eDiscover contains articles about RISC OS, Acorn and the BBC Micro Helpforce eDiscover contains articles about Amiga and AmigaOS

Type your comment into the box below