欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

設(shè)計(jì)模式-中介者模式

場(chǎng)景:服務(wù)端與客戶端通過(guò)webSocket方式通話,websocket充當(dāng)中介

站在用戶的角度思考問題,與客戶深入溝通,找到旌德網(wǎng)站設(shè)計(jì)與旌德網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)虛擬主機(jī)、企業(yè)郵箱。業(yè)務(wù)覆蓋旌德地區(qū)。

abstract class TongXinObject
    {        

        protected Agency agency;
        public TongXinObject(Agency _agency)
        {
            agency = _agency;
        }
        abstract public void SendMsg(string msg);
        abstract public void ReviceMsg(string sender, string msg);
    }
    class Service : TongXinObject
    {
        public string Name = "

總結(jié):服務(wù)端與客戶端完全脫離耦合,職責(zé)相當(dāng)明確。
優(yōu)點(diǎn):減少耦合,交互的過(guò)程獨(dú)立成單獨(dú)的類(中介類)。
缺點(diǎn):中介類的職責(zé)過(guò)于龐大,不好維護(hù)。

中介者+職責(zé)鏈的代碼如下,純粹練手,是為了模式而模式,實(shí)際開發(fā)可別這么做。

//TongXinObject和上面一樣

//職責(zé)···把上面中介中的if else 抽象出來(lái)
abstract class ZhiZe
    {
        public Service service { get; set; }

        public Client1 client1 { get; set; }

        public Client2 client2 { get; set; }
        public ZhiZe(Service _service, Client1 _client1, Client2 _client2)
        {
            service = _service;
            client1 = _client1;
            client2 = _client2;
        }
        public ZhiZe superZhiZe { get; set; }
        public void SetSuperZhiZe(ZhiZe _zhiZe)
        {
            superZhiZe = _zhiZe;
        }
        abstract public void TuiSongMsg(TongXinObject tongXinObject, string msg);
    }
    class Client1ZhiZe : ZhiZe
    {
        public Client1ZhiZe(Service _service, Client1 _client1, Client2 _client2) : base(_service, _client1, _client2)
        {
        }

        public override void TuiSongMsg(TongXinObject tongXinObject, string msg)
        {
            if (tongXinObject == client1)
            {
                service.ReviceMsg(client1.Name, msg);
                client2.ReviceMsg(client1.Name, msg);
            }
            else
            {
                superZhiZe.TuiSongMsg(tongXinObject, msg);
            }
        }
    }
    class Client2ZhiZe : ZhiZe
    {
        public Client2ZhiZe(Service _service, Client1 _client1, Client2 _client2) : base(_service, _client1, _client2)
        {
        }

        public override void TuiSongMsg(TongXinObject tongXinObject, string msg)
        {
            if (tongXinObject == client2)
            {
                service.ReviceMsg(client2.Name, msg);
                client1.ReviceMsg(client2.Name, msg);
            }
            else
            {
                superZhiZe.TuiSongMsg(tongXinObject, msg);
            }
        }
    }
    class ServiceZhiZe : ZhiZe
    {
        public ServiceZhiZe(Service _service, Client1 _client1, Client2 _client2) : base(_service, _client1, _client2)
        {
        }

        public override void TuiSongMsg(TongXinObject tongXinObject, string msg)
        {
            if (tongXinObject == service)
            {
                client1.ReviceMsg(service.Name, msg);
                client2.ReviceMsg(service.Name, msg);
            }
            else
            {
                Console.WriteLine("over");
            }
        }
    }

//中介
abstract class Agency
    {       
        public ZhiZe ZhiZe1 { get; set; }

        public ZhiZe ZhiZe2 { get; set; }

        public ZhiZe ZhiZe3 { get; set; }

        public Agency()
        {

        }
        public void SetZhiZe(Service service, Client1 client1, Client2 client2)
        {
            ZhiZe1 = new Client1ZhiZe(service, client1, client2);
            ZhiZe2 = new Client2ZhiZe(service, client1, client2);
            ZhiZe3 = new ServiceZhiZe(service, client1, client2);

            ZhiZe1.SetSuperZhiZe(ZhiZe2);
            ZhiZe2.SetSuperZhiZe(ZhiZe3);
        }
        abstract public void TuiSongMsg(TongXinObject obj, string msg);
    }
    class WebSocket : Agency
    {
        public override void TuiSongMsg(TongXinObject obj, string msg)
        {
            ZhiZe1.TuiSongMsg(obj, msg);
        }
    }

    //前端:
    static void Main(string[] args)
        {
            //Agency agency = new WebSocket();
            //Service service = new Service(agency);
            //Client1 client1 = new Client1(agency);
            //Client2 client2 = new Client2(agency);
            //agency.service = service;
            //agency.client1 = client1;
            //agency.client2 = client2;

            //service.SendMsg("零點(diǎn)停電維護(hù)");
            //client1.SendMsg("我嬲!");
            //client2.SendMsg("尼瑪,我PC端不接火");

            //Console.Read();

            中介者模式.職責(zé)鏈中介.Agency agency = new 中介者模式.職責(zé)鏈中介.WebSocket();
            Service service = new Service(agency);
            Client1 client1 = new Client1(agency);
            Client2 client2 = new Client2(agency);            
            agency.SetZhiZe(service, client1, client2);

            service.SendMsg("零點(diǎn)停電維護(hù)");
            client1.SendMsg("我嬲!");
            client2.SendMsg("尼瑪,我PC端不接火");

            Console.Read();
        }
    }

文章題目:設(shè)計(jì)模式-中介者模式
轉(zhuǎn)載注明:http://aaarwkj.com/article44/gihhee.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、域名注冊(cè)、建站公司、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站制作電子商務(wù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

国产精品无遮挡猛进猛出| 日韩在线视频一区二区三| 国产一级一片内射视频| 成人激情视频在线观看| 国产丝袜美腿在线观看| 欧美精品熟妇乱黑人最大| 韩国av高清在线观看| 粉嫩在线一区二区懂色| 另类视频在线免费观看| 精品国产91乱码一区二区三区| 亚洲理论在线观看电影| 亚洲最大黄色免费在线观看| 中文字幕日韩欧美一区二区| 亚洲午夜福利天堂社区| 日韩国产一区二区三区精品| 亚洲专区综合红桃av| 蜜臀人妻久久一区二区三| 亚洲精品一区二区三区不卡| 国内精品人妻在线中文字幕| 国产精品又大又黑又长又粗| 色吊最新在线视频免费观看| 久章草在线免费视频播放| 亚洲中文字幕一区乱码| 日韩中文字幕视频久久| 精品人妻一区二区三区| 日韩一二三区欧美四五区新| 麻豆印象传媒在线观看| 精品国产不卡在线观看| 久久96国产精品久久秘臀| 亚洲免费视频一二三区| 国产成人午夜视频免费一区| 日本又色又爽又黄的观看| 日本东京热在线免费观看| 美女被男人操国产精品| 国产成年人在线免费观看| av电影网站中文字幕| 精品国产一区二区三级四区| 七十二式性日韩视频| 欧美久久久久综合一区| av天堂资源地址在线观看| 国精品91人妻一区二区|