CSharp · Console
using System;
public class Program
{
public static void Main()
{
BankAccountProxy proxy = new BankAccountProxy("admin");
proxy.Withdraw(100.0);
}
}
public interface IBankAccount {
void Withdraw(double amount);
}
public class RealBankAccount : IBankAccount {
public void Withdraw(double amount) {
Console.WriteLine($"Withdrew {amount} successfully.");
}
}
public class BankAccountProxy : IBankAccount {
private RealBankAccount _realAccount = new RealBankAccount();
private string _role;
public BankAccountProxy(string role) {
_role = role;
}
public void Withdraw(double amount) {
if (_role == "admin") _realAccount.Withdraw(amount);
else Console.WriteLine("Access Denied.");
}
}