定义接口:

public interface ITest
    {
        double GetPrice();

    }

某个类实现接口:

public class Test1 : ITest
    {
        public double GetPrice()
        {
            return 0.32;
        }
    }

定义壳子实体类:

public class Test
    {
        private ITest Itest;

        public Test(ITest itest)
        {
            this.Itest = itest;
        }

        public double GetPrice()
        {
            return this.Itest.GetPrice();
        }
    }

调用:

class Program
    {
        static void Main(string[] args)
        {
            Test test = new Test(new Test1());
            var returnVal = test.GetPrice();
            Console.Write(returnVal);
            Console.Read();
        }
    }

 

posted on 2015-08-11 22:40  USID  阅读(262)  评论(0编辑  收藏  举报