forked from danieldantasdev/DesignPatternsInUse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
29 lines (22 loc) · 1.47 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* This example demonstrates how the Facade pattern can simplify interactions
* with complex cloud storage APIs by providing a unified interface
* (ICloudStorageFacade) for common cloud operations.
* Developers can switch between different cloud providers
* (e.g., AWS S3, Azure Blob Storage) by changing the concrete facade implementation used,
* without altering the application logic that relies on cloud services.
* This approach enhances modularity, reduces dependency on specific cloud providers,
* and makes the application more adaptable to changes in cloud services. */
// Choose the desired cloud storage facade implementation
ICloudStorageFacade cloudStorage = new AwsStorageFacade(); // or new AzureStorageFacade() for Azure
string fileName = "example.txt";
// Simulated file content as a byte array
// For demonstration purposes, let's create a simple string and convert it to a byte array
string textContent = "Hello, Cloud Storage!";
byte[] fileContent = System.Text.Encoding.UTF8.GetBytes(textContent);
// Uploading simulated content to cloud storage
cloudStorage.UploadFile(fileName, fileContent);
// Assuming the download method returns the content we just uploaded
byte[] downloadedContent = cloudStorage.DownloadFile(fileName);
// Optionally, converting the downloaded byte array back to a string to verify the content
string downloadedText = System.Text.Encoding.UTF8.GetString(downloadedContent);
Console.WriteLine($"Downloaded content: {downloadedText}");