天天看點

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

介紹

将抽象部分與它的實作部分分離,使它們都可以獨立地變化。

示例

有一個Message實體類,對它的操作有Insert()和Get()方法,現在使這些操作的抽象部分和實作部分分離。

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

MessageModel

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using System;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using System.Collections.Generic;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using System.Text;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

namespace Pattern.Bridge

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

{

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    /**//// <summary>

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    /// Message實體類

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    /// </summary>

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    public class MessageModel

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        /**//// <summary>

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        /// 構造函數

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        /// </summary>

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        /// <param name="msg">Message内容</param>

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        /// <param name="pt">Message釋出時間</param>

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        public MessageModel(string msg, DateTime pt)

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            this._message = msg;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            this._publishTime = pt;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        }

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        private string _message;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        /// Message内容

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        public string Message

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            get 

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

{ return _message; }

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            set 

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

{ _message = value; }

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        private DateTime _publishTime;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        /// Message釋出時間

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        public DateTime PublishTime

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

{ return _publishTime; }

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

{ _publishTime = value; }

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    }

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

}

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

Message

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    /// 操作Message(Abstraction)

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    public class Message

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        private AbstractMessage _abstractMessage;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        /// 操作Message(Implementor)

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        public AbstractMessage AbstractMessage

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

{ return _abstractMessage; }

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

{ _abstractMessage = value; }

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        /// 擷取Message

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        /// <returns></returns>

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        public virtual List<MessageModel> Get()

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            return _abstractMessage.Get();

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        /// 插入Message

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        /// <param name="mm">Message實體對象</param>

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        public virtual bool Insert(MessageModel mm)

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            return _abstractMessage.Insert(mm);

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

MyMessage

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    /// 操作Message(RefinedAbstraction)

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    public class MyMessage : Message

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        public override List<MessageModel> Get()

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            List<MessageModel> l = base.Get();

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            foreach (MessageModel mm in l)

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

                mm.Message += "(RefinedAbstraction)";

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            }

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            return l;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

AbstractMessage

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    /// 操作Message(Implementor)

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    public abstract class AbstractMessage

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        public abstract List<MessageModel> Get();

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        public abstract bool Insert(MessageModel mm);

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

SqlMessage

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    /// Sql方式操作Message(ConcreteImplementor)

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    public class SqlMessage : AbstractMessage

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            List<MessageModel> l = new List<MessageModel>();

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            l.Add(new MessageModel("SQL方式擷取Message", DateTime.Now));

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        public override bool Insert(MessageModel mm)

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            // 代碼略

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            return true;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

XmlMessage

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    /// Xml方式操作Message(ConcreteImplementor)

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    public class XmlMessage : AbstractMessage

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

            l.Add(new MessageModel("XML方式擷取Message", DateTime.Now));

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

Test

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using System.Data;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using System.Configuration;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using System.Collections;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using System.Web;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using System.Web.Security;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using System.Web.UI;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using System.Web.UI.WebControls;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using System.Web.UI.WebControls.WebParts;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using System.Web.UI.HtmlControls;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

using Pattern.Bridge;

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

public partial class Bridge : System.Web.UI.Page

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

    protected void Page_Load(object sender, EventArgs e)

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        MyMessage m = new MyMessage();

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        m.AbstractMessage = new SqlMessage();

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        Response.Write(m.Insert(new MessageModel("插入", DateTime.Now)));

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        Response.Write("<br />");

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        Response.Write(m.Get()[0].Message + " " + m.Get()[0].PublishTime.ToString());

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

        m.AbstractMessage = new XmlMessage();

樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)
樂在其中設計模式(C#) - 橋接模式(Bridge Pattern)

運作結果

True

SQL方式擷取Message(RefinedAbstraction) 2007-5-13 19:11:19

XML方式擷取Message(RefinedAbstraction) 2007-5-13 19:11:19

參考

<a href="http://www.dofactory.com/Patterns/PatternBridge.aspx" target="_blank">http://www.dofactory.com/Patterns/PatternBridge.aspx</a>

OK

<a href="http://files.cnblogs.com/webabcd/Pattern.rar">[源碼下載下傳]</a>