Skip to content

Instantly share code, notes, and snippets.

@cbilson
Created February 4, 2009 20:42
Show Gist options
  • Save cbilson/58332 to your computer and use it in GitHub Desktop.
Save cbilson/58332 to your computer and use it in GitHub Desktop.
public interface IFileSaverService {
void SaveFile(byte[] bytes, string filename);
}
public class LocalFileSystemSaver : IFileSaverService {
public void SaveFile(byte[] bytes, string filename) {
...
}
}
public class FtpFileSaver : IFileSaverService {
IConnection _connection = null;
public void SaveFile(byte[] bytes, string filename) {
if (_connection == null)
throw new NotConnectedException();
...
}
// FTP is special...you need to login first
public void LoginToFtpSiteFirst(string name, string password) {
_connection = GetConnectionSomehow(name, password);
}
}
public class FileManager {
IFileSaverService _fileSaver;
public void Save(Document doc) {
var bytes = doc.GetBytes();
var fileName = doc.GetFileName();
_fileSaver.SaveFile(bytes, fileName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment