Created
February 4, 2009 20:42
-
-
Save cbilson/58332 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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