-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace design_patterns.src.Proxy | ||
{ | ||
public interface ISuperSecretDatabase | ||
{ | ||
void DisplayDatabaseName(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace design_patterns.src.Proxy | ||
{ | ||
public static class ProxyUsage | ||
{ | ||
public static void SampleOne() | ||
{ | ||
Console.WriteLine("\nProxy Usage Sample One : "); | ||
ISuperSecretDatabase superSecretDatabase = new SuperSecretDatabaseProxy("test_db", "Password"); | ||
superSecretDatabase.DisplayDatabaseName(); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace design_patterns.src.Proxy | ||
{ | ||
/// <summary> | ||
/// Super Secret Database | ||
/// </summary> | ||
public class SuperSecretDatabase(string databaseName) : ISuperSecretDatabase | ||
{ | ||
private readonly string _databaseName = databaseName; | ||
|
||
public void DisplayDatabaseName() | ||
{ | ||
Console.WriteLine("Display database name : " + _databaseName); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace design_patterns.src.Proxy | ||
{ | ||
public class SuperSecretDatabaseProxy(string databaseName, string password) : ISuperSecretDatabase | ||
{ | ||
private SuperSecretDatabase? superSecretDatabase; | ||
private readonly string databaseName = databaseName; | ||
private readonly string password = password; | ||
|
||
public void DisplayDatabaseName() | ||
{ | ||
if (password.Equals("Password")) | ||
{ | ||
if (superSecretDatabase == null) | ||
{ | ||
superSecretDatabase = new(databaseName); | ||
} | ||
superSecretDatabase!.DisplayDatabaseName(); | ||
} | ||
} | ||
} | ||
} |