static void Main(string[] args) { //BuilderExample(); //FactoryExample(); //FactoryMethodExample(); //FactoryMethodExample2(); //ProtoTypeExample(); //SingletonExample(); //AdapterExample(); //BridgeExample(); //CompositeExample(); //DecoratorExample();
FacadeExample();
//Console.WriteLine("Hello World!"); Console.ReadKey(); }
static void FacadeExample() { Mortgage mortgage = new Mortgage();
Customer customer = new Customer("Ann Mckinsey"); bool eligible = mortgage.IsEligible(customer, 125000);
Console.WriteLine("\n" + customer.Name + " has been " + (eligible ? "Approved" : "Rejected")); }
main.cs |
using System; using System.Collections.Generic; using System.Text;
namespace DesignPatterns.Structural_Patterns.Facade { public class Customer { private string name;
public string Name { get => name; private set => name = value; }
public Customer(string name) { Name = name; } } }
Customer.cs |
using System; using System.Collections.Generic; using System.Text;
namespace DesignPatterns.Structural_Patterns.Facade.Subsystem { public class Bank { public bool HasSufficientSavings(Customer c, int amount) { Console.WriteLine("Check bank for " + c.Name); return true; } } }
Bank.cs |
using System; using System.Collections.Generic; using System.Text;
namespace DesignPatterns.Structural_Patterns.Facade.Subsystem { public class Credit { public bool HasGoodCredit(Customer c) { Console.WriteLine("Check credit for " + c.Name); return true; } } }
Credit.cs |
using System; using System.Collections.Generic; using System.Text;
namespace DesignPatterns.Structural_Patterns.Facade.Subsystem { public class Loan { public bool HasNoBadLoans(Customer c) { Console.WriteLine("Check loans for " + c.Name); return true; } } }
Loan.cs |
using System; using System.Collections.Generic; using System.Text; using DesignPatterns.Structural_Patterns.Facade.Subsystem;
namespace DesignPatterns.Structural_Patterns.Facade { public class Mortgage { private Bank bank = new Bank(); private Loan loan = new Loan(); private Credit credit = new Credit();
public bool IsEligible(Customer cust, Int32 amount) { Console.WriteLine("{0} applies for {1:C} loan\n", cust.Name, amount); bool eligible = true;
if (bank.HasSufficientSavings(cust, amount) != true) { eligible = false; } else if(loan.HasNoBadLoans(cust) != true) { eligible = false; } else if(credit.HasGoodCredit(cust) != true) { eligible = false; }
return eligible; }
} }
Mortgage.cs |
참고 사이트
'C# 디자인패턴' 카테고리의 다른 글
14# Proxy패턴 Structural Patterns (0) | 2019.06.19 |
---|---|
13# Flyweight패턴 Structural Patterns (0) | 2019.06.19 |
11# Decorator패턴 Structural Patterns (0) | 2019.06.03 |
10# Composite패턴 Structural Patterns (0) | 2019.06.03 |
09# Bridge패턴 Structural Patterns (0) | 2019.05.29 |