分析模式:随感——多重动态分类的模拟

  1 None.gif using  System;
  2 None.gif
  3 None.gif namespace  MultiTypeTry
  4 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
  5InBlock.gif    
  6InBlock.gif    public class IObservationB
  7ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
  8InBlock.gif        private Observation parent;
  9InBlock.gif        public Observation Parent
 10ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 11ExpandedSubBlockStart.gifContractedSubBlock.gif            set dot.gif{ parent = value;}
 12ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn parent; }
 13ExpandedSubBlockEnd.gif        }

 14ExpandedSubBlockStart.gifContractedSubBlock.gif        virtual public void Confirm()dot.gif{}
 15InBlock.gif        
 16ExpandedSubBlockEnd.gif    }

 17InBlock.gif
 18InBlock.gif    public class Hypothesis : IObservationB
 19ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 20InBlock.gif        override public void Confirm()
 21ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 22InBlock.gif                Console.WriteLine("This is Hypothesis!");
 23ExpandedSubBlockEnd.gif            }

 24ExpandedSubBlockEnd.gif    }

 25InBlock.gif
 26InBlock.gif    public class Projection : IObservationB
 27ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 28InBlock.gif        override public void Confirm()
 29ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 30InBlock.gif                Console.WriteLine("This is Projection!");
 31ExpandedSubBlockEnd.gif            }

 32ExpandedSubBlockEnd.gif    }

 33InBlock.gif
 34InBlock.gif    public class ActiveObservation : IObservationB
 35ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 36InBlock.gif        override public void Confirm()
 37ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 38InBlock.gif            Console.WriteLine("This is ActiveObservation!");
 39ExpandedSubBlockEnd.gif        }

 40ExpandedSubBlockEnd.gif    }

 41InBlock.gif
 42InBlock.gif    public class IObservationA
 43ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 44InBlock.gif        private Observation parent;
 45InBlock.gif        public Observation Parent
 46ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 47ExpandedSubBlockStart.gifContractedSubBlock.gif            set dot.gif{ parent = value;}
 48ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn parent; }
 49ExpandedSubBlockEnd.gif        }

 50ExpandedSubBlockStart.gifContractedSubBlock.gif        virtual public void Observe()dot.gif{}
 51ExpandedSubBlockEnd.gif    }

 52InBlock.gif
 53InBlock.gif    public class Measurement : IObservationA
 54ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 55InBlock.gif        override public void Observe()
 56ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 57InBlock.gif            Console.WriteLine("This is Measurement!");
 58ExpandedSubBlockEnd.gif        }

 59ExpandedSubBlockEnd.gif    }

 60InBlock.gif
 61InBlock.gif    public class CategoryObservation : IObservationA
 62ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 63InBlock.gif        override public void Observe()
 64ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 65InBlock.gif             Console.WriteLine("This is CategoryObservation!");
 66ExpandedSubBlockEnd.gif        }

 67ExpandedSubBlockEnd.gif    }

 68InBlock.gif
 69InBlock.gif
 70InBlock.gif    public class Observation 
 71ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 72InBlock.gif        public static IObservationA InstanceA;
 73InBlock.gif        public static IObservationB InstanceB;
 74InBlock.gif        public Observation(IObservationA iObservationA,IObservationB iObservationB)  
 75ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 76InBlock.gif            InstanceA = iObservationA;
 77InBlock.gif            InstanceA.Parent = this;
 78InBlock.gif            InstanceB = iObservationB;
 79InBlock.gif            InstanceB.Parent = this;
 80ExpandedSubBlockEnd.gif        }

 81InBlock.gif
 82InBlock.gif        public static implicit operator IObservationA(Observation ob)
 83ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 84InBlock.gif            return InstanceA;
 85ExpandedSubBlockEnd.gif        }

 86InBlock.gif
 87InBlock.gif        public static implicit operator IObservationB(Observation ob)
 88ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 89InBlock.gif            return InstanceB;
 90ExpandedSubBlockEnd.gif        }

 91InBlock.gif
 92ExpandedSubBlockEnd.gif    }

 93InBlock.gif
 94InBlock.gif    public class TestApp
 95ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 96InBlock.gif        [STAThread]
 97InBlock.gif        public static void Main()
 98ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 99InBlock.gif            IObservationA a = new CategoryObservation();
100InBlock.gif            IObservationB b = new Hypothesis();
101InBlock.gif
102InBlock.gif            Observation ob = new Observation(a,b);
103InBlock.gif            
104InBlock.gif            ((IObservationA)ob).Observe();
105InBlock.gif            ((IObservationB)ob).Confirm();
106InBlock.gif
107InBlock.gif            //ob.Observe();
108InBlock.gif
109InBlock.gif            Console.ReadLine();
110InBlock.gif
111ExpandedSubBlockEnd.gif        }

112ExpandedSubBlockEnd.gif    }

113ExpandedBlockEnd.gif}

114 None.gif

        先把代码贴上来吧。自己觉得似乎就是一个多接口继承的变种,好象离真正的多重动态分类差的远了些。恩。思考中。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值