定义接口:
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(); } }
时间: 2024-10-06 10:40:39