浅谈门面模式

举一个通俗的例子,购买衣服、电器、首饰
首先建立相应的物品类


//衣服类
public class Clothing
{
public Clothing getClothing()
{
return Clothing;
}
}

//电器类
public class Ele
{
public Ele getEle()
{
return Ele;
}
}

//首饰类
public class Jewelry
{
public Jewelry getJewelry()
{
return Jewelry;
}
}

/**--------------------------按照传统方式---------------------------*/

public class Buy
{
//你需要到服饰店
Clothing c = new Clothing();
c.getClothing(); //购买到衣服

//接着去电器店
Ele c = new Ele();
c.getEle(); //购买到电器

//然后去首饰店
Jewelry c = new Jewelry();
c.getJewelry(); //购买到首饰
}

这样客户类和后台交互很频繁,很枯燥,而且你需要和一个一个商店类打交道,很麻烦,那就换一种方式
/**--------------------------按照门面模式---------------------------*/


//创建购物中心类
public class ShopingCenter
{
//到购物中心的服饰店购买
public void clothingStore()
{
Clothing c = new Clothing();
c.getClothing(); //购买到衣服
}

//到购物中心的电器店购买
public void EleStore()
{
Ele c = new Ele();
c.getEle(); //购买到电器
}

//到购物中心的首饰店购买
public void JewelryStore()
{
Jewelry c = new Jewelry();
c.getJewelry(); //购买到首饰
}
}



好了,现在直接去购物中心,不用一家一家跑了

ShopingCenter sc = new ShopingCenter();
sc.clothingStore();
sc.EleStore();
sc.JewelryStore();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值