网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

C#Facade外观模式中天河城购物出现的问题有什么解决方法-创新互联

这期内容当中小编将会给大家带来有关C# Facade外观模式中天河城购物出现的问题有什么解决方法,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

我们提供的服务有:成都网站建设、成都做网站、微信公众号开发、网站优化、网站认证、潘集ssl等。为近1000家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的潘集网站制作公司

一、理论定义

外观模式   把  分散的子系统,集合成一个系统,提供一站式服务。

二、应用举例

需求描述: 聂小倩 和 宁采臣是一对小富则安 的聊斋夫妻。住在比较偏远的小乡村。
今天,两人初次来到大城市广州,听说天河城提供一站式服务,不像小城市那样,买个东西  得  东奔西跑。
在一个地方,就可以买到 自己想要的衣服,电脑,鞋子,Iphone,还可以看大片,
吃冰淇淋,吃真功夫,买化妆品,珠宝首饰。天河城,果然是一宝地啊。
Ok,边走边看。

三、具体编码

1.阿迪达斯

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// 
  /// 阿迪达斯
  /// 
  public class Adidas
  {
    public void Serivce(string something) {
      Console.WriteLine("在阿迪达斯购买了: "+something);
    }
  }
}

2.飞扬影城

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// 
  /// 飞扬影城
  /// 
  public class FeiYangMovie
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在飞扬影城看了一部电影: " + something);
    }
  }
}

3.国美电器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// 
  /// 国美电器
  /// 
  public class GoMe
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在国美电器 买了: " + something);
    }
  }
}

4.哈根达斯

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// 
  /// 哈根达斯
  /// 
  public class HaagenDaz
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在哈根达斯 买了: " + something);
    }
  }
}

5.真功夫

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// 
  /// 真功夫
  /// 
  public class KungFu
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在真功夫 吃了: " + something);
    }
  }
}

6.六福珠宝

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// 
  /// 六福珠宝
  /// 
  public class LukFook
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在六福珠宝 买了: " + something);
    }
  }
}

7.耐克

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// 
  /// 耐克
  /// 
  public class NIKE
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在耐克店 买了: " + something);
    }
  }
}

8.ONLY

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// 
  /// ONLY时装
  /// 
  public class ONLY
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在ONLY时装 买了: " + something);
    }
  }
}

9.苏宁电器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// 
  /// 苏宁电器
  /// 
  public class Suning
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在苏宁电器 买了: " + something);
    }
  }
}

10.Veromoda国际时装品牌

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// 
  /// Veromoda国际时装品牌
  /// 
  public class Veromoda
  {
    public void Serivce(string something)
    {
      Console.WriteLine(something);
    }
  }
}

11.消费者

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// 
  /// 消费店子
  /// 
  public enum ShopOption
  {
    Adidas = 1, DKNY = 2, GoMe = 3,
    NIKE = 4, Suning = 5, Veromoda = 6,
    FeiYangMovie = 7, HaagenDaz = 8, LukFook = 9, KungFu = 10
  }
  /// 
  /// 消费单
  /// 
  public class Bill {
    /// 
    /// 要去的消费店
    /// 
    public ShopOption Item { get; set; }
    /// 
    /// 去这个店要买啥
    /// 
    public string Something { get; set; }
  }
  public class Consumer
  {
    /// 
    /// 消费单
    /// 
    public IList Items { get; set; }
    /// 
    /// 姓名
    /// 
    public string Name { get; set; }
  }
}

12.天河城---一站式服务

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace Com.Design.Gof.Facade
{
  /// 
  /// 天河城
  /// 
  public class TeeMall
  {
    private static readonly Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + @"\Com.Design.Gof.dll");
    /// 
    /// 一站式服务
    /// 
    /// 
    public void OfferService(Consumer consumer) {
      Console.WriteLine("我是: " + consumer.Name+",不差钱,今天来天河城玩: ");
      Console.WriteLine("----------------------------------------------");
      foreach (Bill item in consumer.Items)
      {
        object obj= assembly.CreateInstance("Com.Design.Gof.Facade." + item.Item);
        MethodInfo info = obj.GetType().GetMethod("Serivce");
        info.Invoke(obj, new object[] { item.Something });
      }
      Console.WriteLine();
    }
  }
}

13.主函数调用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.Design.Gof.Facade;
namespace Com.Design.Gof.Test
{
  class Program
  {
    static void Main(string[] args)
    {
      //天河城购物中心
      TeeMall TeeMall = new TeeMall();
      //消费者 1
      Consumer consumer = new Consumer
      {
        Name="聂小倩",
        //消费单
        Items = new List {
         new Bill{ Item=ShopOption.Adidas, Something="运动服"},
         new Bill{ Item=ShopOption.GoMe, Something="苹果IPhone智能手机"},
         new Bill{ Item=ShopOption.FeiYangMovie, Something="<冰河世纪 4>"},
         new Bill{ Item=ShopOption.KungFu, Something="香菇炖鸡"},
          new Bill{ Item=ShopOption.LukFook, Something="金项链"},
        }
      };
      TeeMall.OfferService(consumer);
      //消费者 2
      consumer = new Consumer
      {
        Name = "宁采臣",
        //消费单
        Items = new List {
         new Bill{ Item=ShopOption.FeiYangMovie, Something="《太空一号》"},
         new Bill{ Item=ShopOption.Veromoda, Something="然后去了Veromoda时装,买了一套服装"},
         new Bill{ Item=ShopOption.HaagenDaz, Something="买了一雪糕"},
         new Bill{ Item=ShopOption.Suning, Something="在苏宁看买平板电脑"},
        }
      };
      TeeMall.OfferService(consumer);
      Console.ReadKey();
    }
  }
}

14.运行结果

C# Facade外观模式中天河城购物出现的问题有什么解决方法

15.总结

天河城 TeeMall 理论上应该包括 所有 商场的引用,

这里用反射 避免了这一动作。

上述就是小编为大家分享的C# Facade外观模式中天河城购物出现的问题有什么解决方法了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联成都网站设计公司行业资讯频道。

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文标题:C#Facade外观模式中天河城购物出现的问题有什么解决方法-创新互联
标题路径:http://bjjierui.cn/article/dichpe.html

其他资讯