来说说(Facade)外观模式

外观模式的实用性?

   1.为一个复杂子系统提供一个简单接口。

    2.提高子系统的独立性。

    3.在层次化结构中,可以使用Facade模式定义系统中每一层的入口。

代码实现

using System;
using UnityEngine;


public class AdpaterTestDemo{


	public void testBirdgeMain()
	{
		Mortgage mo = new  Mortgage ();

		Customers cus = new Customers ();
		if(mo.IsEligible(cus))
		{
			Debug.Log ("贷款没问题");
		}
	}
}


public class Mortgage
{
	Bank  mBank = new Bank();
	Credit mCredit = new Credit();
	Loan mLoan = new Loan ();

	public bool IsEligible(Customers customer)
	{
		bool isEligible = true;
		if(!mBank.HasSufficientSavings(customer))
		{
			isEligible = false;
		}
	
		if(!mCredit.HasSufficientSavings(customer))
		{
			isEligible = false;
		}

		if(!mLoan.HasSufficientSavings(customer))
		{
			isEligible = false;
		}
		return isEligible;
	}

}


/// <summary>
/// 外观模式
/// </summary>
public class Customers
{
	private string name;

	public string Name
	{
		set{ name = value; }
		get{ return name;}
	}
}


public class Bank
{
	public bool HasSufficientSavings(Customers c)
	{
		Debug.Log ("Bank : HasSufficientSavings");
		return true;
	}
}

public class Credit
{
	public bool HasSufficientSavings(Customers c)
	{
		Debug.Log ("Credit : HasSufficientSavings");
		return true;
	}
}

public class Loan
{
	public bool HasSufficientSavings(Customers c)
	{
		Debug.Log ("Credit : HasSufficientSavings");
		return true;
	}
}

facade几个要点

 从客户程序的角度来看,Facade模式不仅简化了整个组件系统的接口,同时对于组件内部与外部客户程序来说,从某种程度上也达到了一种“解耦”的效果----内部子系统的任何变化不会影响到Facade接口的变化。

    Facade设计模式更注重从架构的层次去看整个系统,而不是单个类的层次。Facdae很多时候更是一种架构
设计模式。
    注意区分Facade模式、Adapter模式、Bridge模式与Decorator模式。Facade模式注重简化接口,Adapter模式注重转换接口,Bridge模式注重分离接口(抽象)与其实现,Decorator模式注重稳定接口的前提下为对象扩展功能。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值