Proxy Pattern
Summary:Provide a surrogate or placeholder for another object to control access to it.
Sample Code
Code
public class StorageServer
{
private string ServerURL;
public void Connect()
{
System.Console.WriteLine("Connecting to server.");
}
public void UploadFile()
{
System.Console.WriteLine("Uploading a file.");
}
public List<string> ListFiles()
{
System.Console.WriteLine("Listing server files.");
return new List<string>();
}
}
public class StorageProxy
{
StorageServer server = new StorageServer();
public void Connect() => server.Connect();
public void UploadFile() => server.UploadFile();
public List<string> ListFiles() => server.ListFiles();
}
Usage
var storage = new StorageProxy();
storage.Connect();
storage.ListFiles();
Output
Connecting to server.
Listing server files.
Comments
Post a Comment