コード例 #1
0
ファイル: MessageDispatcher.cs プロジェクト: alissonads/Unity
 private static void deliverMessage(IAdvertiser receiver, Message message)
 {
     if (!receiver.HandleMessage(message))
     {
         throw new Exception("NPC can't treat the message");
     }
 }
コード例 #2
0
        //**** client code that does not need to be changed  ***

        /*
         * //LDAF007 - THE CORE
         * Notice that regardless if you pass in BookStoreA or BookStoreB into the method above, this client code does
         * not need to be changed since it will get the correct advertiser automatically using the internal logics
         * within the factories. It is the factories (BookStoreA and BookStoreB) that determines which advertiser to produce.
         * The same goes for choosing which book distributor to produce.
         *
         * The benefit of the Abstract Factory pattern is that it allows you to create a groups of products
         * (the distributors and the advertisers) without having to know the actual class of the product being produced.
         * The result is that you can have client code that does not need to be changed when  the internal logic of
         * the factories on which product to produce changed.
         */
        public static void Advertise(IBookStore s)
        {
            //LDAF004
            IAdvertiser a = s.GetAdvertiser();

            a.Advertise();
        }
コード例 #3
0
ファイル: Message.cs プロジェクト: alissonads/Unity
 public Message(Message other)
 {
     sender    = other.sender;
     receiver  = other.receiver;
     msg       = (string)other.msg.Clone();
     extraInfo = other.extraInfo;
 }
コード例 #4
0
ファイル: Message.cs プロジェクト: alissonads/Unity
 public Message(IAdvertiser sender, IAdvertiser receiver, string msg, object extraInfo = null)
 {
     this.sender    = sender;
     this.receiver  = receiver;
     this.msg       = msg;
     this.extraInfo = extraInfo;
 }
コード例 #5
0
        public IAdvertiser GetAdvertiser()
        {
            IAdvertiser advertiser = null;

            switch (_location)
            {
            case CustomerLocation.EastCoast:
                advertiser = new RedAdvertiser();
                break;

            case CustomerLocation.WestCoast:
                advertiser = new BlueAdvertiser();
                break;

            default:
                break;
            }
            return(advertiser);
        }
コード例 #6
0
ファイル: MessageDispatcher.cs プロジェクト: alissonads/Unity
 public static void DispatchMessage(IAdvertiser sender, IAdvertiser receiver, string message, object extraInfo = null)
 {
     deliverMessage(receiver, new Message(sender, receiver, message, extraInfo));
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: zebpayshambhu/shambhuApp
        private static void Advertise(IBookStore bookStore)
        {
            IAdvertiser obj = bookStore.GetAdvertiser();

            obj.Advertise();
        }
コード例 #8
0
        //**** client code that does not need to be changed  ***
        private static void Advertise(IBookStore s)
        {
            IAdvertiser a = s.GetAdvertiser();

            a.Advertise();
        }