Re: Instanceof design doubt in Java
David wrote:
Eric, I have to use "instanceof" because is not the same to copy a
file from a shared folder (using CopyType class with java.io classes)
than from a remote ftp site (using FtpTransfer with FTPClient, for
example).
If you implement it the way you did, no. If you think object-
oriented you could. What is common to all copying? That data
has to go from A to B. So you have a DataSource and a DataSink.
Both can be represented as InputStream and OutputStream.
So instead of get and put as methods, define
public abstract InputStream getDataSource();
public abstract OutputStream getDataSink();
and implement one copy-method:
public abstract class CopyClass{
public void copy(CopyClass source, CopyClass sink){
InputStream is = source.getInputStream();
OutputStream os = source.getOutputStream();
byte[] buf = new byte[4096];
int read;
while ((read = is.read(buf)) != -1){
os.write(buf, 0, read);
}
}
}
I think it's a bit complicate.
You think complicated ;-)
Regards, Lothar
--
Lothar Kimmeringer E-Mail: spamfang@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!