Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IDatastore
- {
- string GetSomeData(string key);
- }
- public class FileDatastore : IDatastore
- {
- public string GetSomeData(string key)
- {
- return File.ReadAllText($@"C:\foo\bar\{key}.txt");
- }
- }
- public class WebDatastore : IDatastore
- {
- public string GetSomeData(string key)
- {
- return new WebClient().DownloadString($"http://foo.com/bar/{key}");
- }
- }
- public class SomeBusinessLogicClass
- {
- private IDatastore _datastore;
- public SomeBusinessLogicClass(IDatastore datastore)
- {
- _datastore = datastore;
- }
- public void DoStuff()
- {
- var value = _datastore.GetSomeData("foo");
- Console.WriteLine(value);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement